Html 使用条件注释针对 IE8 是否有效?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/167657/
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
Will targeting IE8 with conditional comments work?
提问by Devon
When IE8 is released, will the following code work to add a conditional stylesheet?
当 IE8 发布时,以下代码是否可以添加条件样式表?
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="ie-8.0.css" />
<![endif]-->
I've read conflicting reports as to whether this works with the beta. I'm hoping someone can share their experience. Thanks.
我读过关于这是否适用于测试版的相互矛盾的报告。我希望有人可以分享他们的经验。谢谢。
采纳答案by Konrad Rudolph
It worked for me –?both in quirks mode and in standards compliance mode. However, it does notwork when switching to IE8 compatibility mode.
它对我有用——无论是在怪癖模式还是在标准合规模式下。但是,它并没有切换到IE8兼容模式下工作。
回答by scunliffe
One thing to note:
需要注意的一件事:
It does work, BUTif you are loading the page/site local network (e.g. Intranet)it will load in IE7mode by default!(update - localhost[*] is a special case, that doesrender in standards mode)
它确实有效,但是如果您正在加载页面/站点本地网络(例如 Intranet),它将默认以IE7模式加载!(更新-本地主机[*]是一种特殊的情况下,即没有在标准模式渲染)
This goes against MSFT's original statement of going STANDARDS by default.
这违背了 MSFT 最初关于默认采用 STANDARDS 的声明。
e.g.
例如
http://127.0.0.1/mysite/mypage.php <-- IE8 by default (updated!)
http://localhost/mysite/mypage.php <-- IE8 by default (updated!)
http://machinename/mysite/mypage.php <-- IE7 by default
http://192.168.100.x/mysite/mypage.php <-- IE7 by default
http://google.com/ <-- IE8 by default
[*] - Scott Dickens [MSFT] noted in a comment here on the IE Blogthat localhost was a special scenario in the Intranet (often used to develop Internet sites) thus would render in Standards mode by default.
[*] - Scott Dickens [MSFT] 在IE 博客的评论中指出,localhost 是 Intranet 中的一个特殊场景(通常用于开发 Internet 站点),因此默认情况下会以标准模式呈现。
To test what mode a page in IE8 is really rendering in, you can use check the developer tools or use this bookmarklet code (only works in IE8):
要测试 IE8 中的页面真正呈现的模式,您可以使用检查开发人员工具或使用此书签代码(仅适用于 IE8):
javascript:
var vMode=document.documentMode;
var rMode='IE5 Quirks Mode';
if(vMode==8){
rMode='IE8 Standards Mode';
} else if(vMode==7){
rMode='IE7 Strict Mode';
}
alert('Rendering in: '+rMode);
回答by Konrad Rudolph
Tools/Compatability view settings
工具/兼容性视图设置
uncheck them all
全部取消选中
回答by Konrad Rudolph
Thank you for your help. I've discovered the solution, apparently the problem was having each style sheet use its own title attribute. Once I took the title off all but the main style sheet, no prob.
感谢您的帮助。我发现了解决方案,显然问题是让每个样式表使用自己的标题属性。一旦我从除主样式表之外的所有内容中取下标题,就没有问题了。
This is a weird issue unique to IE8 - and although I've been told its supposed to work that way, something to do with "Stylesheet Preference" - it only serves to create problems since the solution requires you remove the title which could be helpful when scripting, etc - when you need to call the style sheet.
这是 IE8 独有的一个奇怪问题 - 尽管我被告知它应该以这种方式工作,但与“样式表首选项”有关 - 它只会产生问题,因为解决方案要求您删除可能有帮助的标题在编写脚本等时 - 当您需要调用样式表时。
In any case, not sure if this is a bug, or its supposed to be that way, but I hope Microsoft investigates further.
无论如何,不确定这是否是一个错误,或者它应该是那样的,但我希望微软进一步调查。
Thanks
谢谢
回答by Sankho Mallik
Why even bother writing a separate stylesheet for IE8?
为什么还要为 IE8 编写单独的样式表?
If you've already debugged for IE7, you can force IE8 into compatibility mode, and thus display your code as though IE8 were IE7.
如果您已经针对 IE7 进行了调试,则可以强制 IE8 进入兼容模式,从而将您的代码显示为 IE8 是 IE7。
All you gotta do is put this RIGHT BELOW the opening head tag. Anywhere else and it won't work.
你所要做的就是把这个放在开头标签的正下方。在其他任何地方,它都行不通。
And then that's a half hour or so less work on average per project, no intense debugging for IE8 needed!
然后每个项目平均减少半小时左右的工作,不需要对 IE8 进行大量调试!
Even Msn.com does this - kind of ironic, eh?
甚至 Msn.com 也这样做 - 有点讽刺,嗯?
Wrote a blog post about it recently: http://blog.sankhomallik.com/2009/11/16/stop-wasting-time-debugging-on-ie8-when-you-dont-have-to-or-get-ie8-to-behave-like-ie7/
最近写了一篇关于它的博客文章:http: //blog.sankhomallik.com/2009/11/16/stop-wasting-time-debugging-on-ie8-when-you-dont-have-to-or-get- ie8-to-behave-like-ie7/
回答by Eze
IE8 renders pretty nice compared to IE7, I have stylesheets for IE6, IE7 and IE8; at first i thought conditional comments were not working for IE8 after a bit of experimentation i found some rules were not beeing applied by IE8 just because i needed to put the ancestor or parent class first, e.g. i had a class like
与 IE7 相比,IE8 渲染得相当不错,我有 IE6、IE7 和 IE8 的样式表;起初我认为条件注释在经过一些实验后不适用于 IE8 我发现一些规则没有被 IE8 应用,只是因为我需要把祖先或父类放在第一位,例如我有一个类
.niceclass {some:properties;more:properties;}
.niceclass {some:properties;more:properties;}
it worked onlyif i changed it for something like:
只有当我将其更改为以下内容时它才有效:
.parentclass .niceclass {some:properties;more:properties;}
or
.parentclass .niceclass {some:properties;more:properties;}
或者
#parentselector .niceclass {some:properties;more:properties;}
#parentselector .niceclass {some:properties;more:properties;}
btw in my IE8-only css i have only one overriding rule, the rest is rendered almost like firefox, though thats not making me leave FF anyway!.
顺便说一句,在我的 IE8-only css 中,我只有一个最重要的规则,其余的几乎像 firefox 一样呈现,尽管这并没有让我离开 FF!
回答by Carsten
For my part I wanted to use rounded borders using css. IE8 on Vista does not support such. And since the graphics were so that the rounded borders would show a nice rounded shadow as well, the page looked terrible in IE8.
就我而言,我想使用 css 使用圆角边框。Vista 上的 IE8 不支持此类。而且由于图形使圆形边框也显示出漂亮的圆形阴影,因此页面在 IE8 中看起来很糟糕。
I tried using conditional comments, but to no avail, IE8 would not evaluate the if IE expression and thus would not include the external stylesheet.
我尝试使用条件注释,但无济于事,IE8 不会评估 if IE 表达式,因此不会包含外部样式表。
Then I had a look at putting it into quirks / compatiblity mode, however, this still did not work as the CSS hacks I had used did no longer work for the IE8.
然后我查看了将其置于 quirks/compatblity 模式,但是,这仍然不起作用,因为我使用的 CSS hacks 不再适用于 IE8。
Last but least I found a working CSS hack that will render the page correctly when in compatibility mode.
最后但最不重要的是,我发现了一个有效的 CSS hack,它可以在兼容模式下正确呈现页面。
* + html #test[id] { color:lime }
Now, I do not know if this works for IE7 or below, so you would have at least three different hacks for each IE release you want to support, e.e.
现在,我不知道这是否适用于 IE7 或更低版本,因此对于您要支持的每个 IE 版本,您至少有三种不同的 hack,ee
* + html #test,
html+body #test,
* html body #test
{ color:lime }
I wonder what the next regression of the Internet Exploiter will behold for us.
我想知道 Internet Exploiter 的下一次回归会给我们带来什么。