CSS:IE 9 hack for margin-left?\9; 没有效果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15215891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS: IE 9 hack for margin-left? \9; has no effect
提问by MeltingDog
I have an element that currently has margin-left: -110px
of course, this works with my design in all browsers except IE. With IE I need to make it margin-left: 10px
我margin-left: -110px
当然有一个当前具有的元素,这适用于我在除 IE 之外的所有浏览器中的设计。使用 IE 我需要做到margin-left: 10px
Normally, I would do my IE hacks by adding \9;
, such as:
通常,我会通过添加来做我的 IE 黑客\9;
,例如:
margin-left: 10px;
but it doesnt seem to work with margins. Does anyone know a way to acheive this? Many thanks!
但它似乎不适用于边距。有谁知道实现这一目标的方法?非常感谢!
<div id="nav">
<ul>
<li id="newstab">News</li>
<li id="offerstab">Offers</li>
<li id="specialsstab">Specials</li>
</ul>
</div>
#nav {
position:absolute;
margin-left: -110px;
margin-left: 10px;
margin-top: 160px;
writing-mode:tb-rl;
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-o-transform: rotate(90deg);
white-space:nowrap;
}
采纳答案by MeltingDog
Found it was
发现是
writing-mode:tb-rl;
IE didnt like.
IE 不喜欢。
This site was useful:
这个网站很有用:
回答by Blender
If you really need to, you can use an IE conditional block:
如果确实需要,可以使用 IE 条件块:
<link href="style.css" rel="stylesheet" />
<!--[if lt IE 10]>
<style type="text/css">
.thing {
margin-left: 10px;
}
</style>
<![endif]-->
回答by sian chen
.class {
text-align:right;
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
margin-left: 30px
}
margin-left: 90px;
}
You can write the specific css for IE, then overwrite other css for other browser.
您可以为 IE 编写特定的 css,然后为其他浏览器覆盖其他 css。
回答by seemly
Why are you using margin-left, when you are also using position:absolute? You won't ever gain the desired effect of a margin when using position absolute (but that is not the actualissue here).
当您还使用 position:absolute 时,为什么要使用 margin-left?使用绝对位置时,您永远不会获得预期的保证金效果(但这不是这里的实际问题)。
When using position absolute, you should always define the elements default datum point consisting of at least a top/bottom and left/right position - in your case, top:0; left:110px; (this is assuming the absolute positioned element is within a position:relative; parent container).
使用绝对位置时,您应该始终定义元素的默认基准点,至少包括顶部/底部和左侧/右侧位置 - 在您的情况下,top:0;左:110px;(这是假设绝对定位元素在一个位置:相对;父容器内)。
You are allowing the browsers to assume what you want to display, rather than actually defining and telling the browsers what you want to display - You should be doing this without fail on everything you build in CSS.
您允许浏览器假设您想要显示的内容,而不是实际定义和告诉浏览器您想要显示的内容 - 您应该在使用 CSS 构建的所有内容上都做到这一点。
In not strictly defining where you want an element to sit using absolute positioning, you are asking for trouble in IE (especially lt IE9).
在使用绝对定位没有严格定义您希望元素位于何处时,您会在 IE 中遇到麻烦(尤其是 lt IE9)。
回答by Sahil Popli
You can use like this
你可以这样使用
<!--[if lte IE 7]> <html class="ie7"> <![endif]-->
<!--[if IE 8]> <html class="ie8"> <![endif]-->
<!--[if IE 9]> <html class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html> <!--<![endif]-->
Then in your CSS, you would target IE7, IE8 or IE9 like this:
然后在你的 CSS 中,你可以像这样定位 IE7、IE8 或 IE9:
.element {
margin-left: 20px;
}
.ie7 .element {
margin-left: 10px;
}
.ie8 .element {
margin-left: 15px;
}
.ie9 .element {
margin-left: 10px;
}
Now every browser will have a left margin of 20px on the element in question, but IE7, IE8 and IE0 will have a left margin of 10px, 15px and 10px respectively.
现在每个浏览器在相关元素上的左边距为 20px,但 IE7、IE8 和 IE0 的左边距分别为 10px、15px 和 10px。