仅在 CSS 文件中为 IE 指定 CSS 属性

Specify CSS properties for the IE only in the CSS file


实际上我需要指定这个 属性

margin-left:-20px;

仅适用于 IE-11 和 CSS 文件中所有浏览器的其余属性

.navigator li a span {
    display: block;
    float: right;
    width: 80px;
    height: 50px;
    margin-right: -10px;
    margin-left:-20px;
    }

有没有办法做到这一点,因为我尝试了很多解决方案都没有用
提前致谢!

听起来您的问题可以通过浏览器条件样式之外的其他方式解决,请先尝试一下,但无论如何:

对于 IE 10 和 11,您可以使用:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}

不过请注意,它将识别 IE 10 和 11。

来源:https://philipnewcomer.net/2014/04/target-internet-explorer-10-11-css/

您可能还想看看这个:

http://marxo.me/target-ie-in-css/


对于 IE 9 及更低版本,您可以使用:

您为此创建一个单独的样式表,然后使用它来将其包含在您的 HTML 中。

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

例如,如果您想要以 IE 7 为目标,您可以这样做。您可以将版本号更改为您想要的版本号。

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

然后您还可以定位比特定版本更低或更高的版本:

低于 IE 8 和 IE 8:

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

高于 IE 8:

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

请注意,您可以使用 ltltegtgte

我写的很简单,只支持IE 11+

<style type="text/css">
  _:-ms-fullscreen, :root .msie11 { color: blue; }
</style>

// or you can try this

<style>
  @media all and (-ms-high-contrast:none)
    {         
      *::-ms-backdrop, .foo { color: red } /* IE11 */
    }
</style>

当然还有 div...

<div class="msie11">
    This is an Internet Explorer 11 and greater CSS Hack
<div>

因此文本在 Internet Explorer 11 及更高版本中显示为蓝色。玩得开心。

如需更多参考,您可以查看给定的 link

Reference