【问题标题】:How to hack css Inline style only on IE?如何仅在 IE 上破解 css 内联样式?
【发布时间】:2018-10-05 04:18:13
【问题描述】:

如何仅在 IE 上破解 css 内联样式?

在所有版本中只在 IE 上破解 css 内联样式,我该怎么做?

这样

<div style = "
               color: #eee;
               border: 1px solid #000;
for ie only // line-height : 32px;     
             "/>

【问题讨论】:

  • @ViniciusMonteiro 仅适用于 IE6/7
  • 在问这样的问题时,请始终指定您需要它工作的 IE 版本。另外,请详细说明您要修复的 IE 中的问题;可能存在不需要 IE hack 的替代解决方案。
  • @JochemQuery 这个问题涵盖了 IE 的所有版本,我进行了测试以确保。
  • 这里是一个详尽的 css hack 列表,您可以使用内联和单独的样式表 abbasharoon.me/css-hacks-internet-explorer

标签: css internet-explorer


【解决方案1】:

您需要在属性名称前添加*,这将只针对IE7,因此您需要将此line-height : 32px; 写为*line-height : 32px;

我意识到你想为每个 IE 提供 hack,所以你开始

  • 对于 IE6 - _
  • 对于 IE7 - *
  • 对于 IE8 - \0
  • 对于 IE9 - \9

专门使用 CSS Only 为 IE10 声明样式

@media all and (-ms-high-contrast: none) { 
   /* This won't go inline but can be used at document level*/
   /* Declaration Blocks Goes Here*/
}

您可以阅读here,了解有关如何使用@media 查询声明仅限 IE 样式的更多信息


我仍然建议您使用条件 cmets,这将使您的生活更轻松,而不是声明内联样式。

【讨论】:

  • 还有 8,9,10 我该怎么办?
  • OP 询问所有 IE 版本,你为什么要给 IE7 具体建议?
  • @JochemQuery 我真的不知道我是怎么回答的只有IE7,我想现在该睡觉了
  • 奇怪我以为这个问题也只是关于IE7
  • 不错的编辑,但我仍然建议 OP 不要将内联 css 用于这么多规则。会把它弄得一团糟,不是说这不是一个好的答案
【解决方案2】:
<!--[if IE]>
    div.classname{
        line-height: 32px; //ie only 
    }
<![endif]-->

来源:http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

编辑:

  • 给那个 div 一个类
  • 为该类指定特定的 ie 样式。

【讨论】:

  • 我想使用css内联
  • @user3215821 为什么会这样?有什么具体原因吗?
【解决方案3】:
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
   #myElement {
        /* Enter your style code */
   }
}

【讨论】:

    猜你喜欢
    • 2016-04-09
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    相关资源
    最近更新 更多