html - 在一个 CSS 类中组合不同的用户代理属性

标签 html css google-chrome internet-explorer-8 cross-browser

我想在用户键入错误内容时将轮廓颜色放入文本框。问题是 IE8 不支持 outline 属性(至少我测试没有成功)所以我改用 border :

但我想对 IE8 使用 border,对支持它的浏览器使用 outline

.myclass
{
  border: ; // IE8 should use this
  outline: ; // Browser that support it must ignore the above one and get this.
}

我用 IE8 和 Chrome 进行了测试,这两个属性都在 Chrome 中应用,而在 IE8 中只应用了边框。

例子:

.myclass
{
  border: 1px solid red;
  outline:#00FF00 dotted thick;
}

http://jsfiddle.net/puD97/

谢谢。

最佳答案

谁说IE8不支持outline属性?

如果你想为 IE 和其他浏览器使用不同的样式,请使用 IE 特定的样式表,使用 IE 特定的 cstylesheet 注释

<!-- This will be ignored by all browsers but IE -->

<!--[if IE]>
    <link rel="stylesheet" type="text/css" href="ie-only.css" />
<![endif]-->

或针对任何特定的 IE 版本

<!--[if IE 8]>
    <link rel="stylesheet" type="text/css" href="ie7.css">
<![endif]-->

或者在你的页面中使用这个

<!--[if IE 8]>
    <style>
      /* Styles goes here */
    </style>
<![endif]-->

关于html - 在一个 CSS 类中组合不同的用户代理属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13514117/

相关文章:

javascript - 使用 Javascript 将 img 元素拆分为四个大小相等的较小 img 元素

html - 如何允许 HTML 在指定点中断?

css - 将 div 与所有其他框顶部对齐

css - 在 Chrome/IE9 中去除图像边框

javascript - 在电子邮件类型的 HTML 输入字段中输入空格时,Chrome 不会触发 onchange 事件

javascript - 向 HTML 元素添加附加信息(元)

javascript - 清理 HTML 代码中的样式属性

css - 如何减小字体文件大小?

javascript - 使用 Jquery 创建具有点击和悬停功能的菜单

google-chrome - 如何在 chrome 开发工具源 View 中显示控制台