做双斜线直接IE使用特定的CSS? [英] Do double forward slashes direct IE to use specific css?

查看:200
本文介绍了做双斜线直接IE使用特定的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现了一些很怪,而开发一个网站。虽然试图获得一个div元素在屏幕的顶部显示,我注意到,我没有实现,除了旧版本的IE浏览器的任何一个期望的结果。为了测试一些不同的code,而不是删除故障线路,我用'//'评出来(我不是真的,即使知道,在CSS的工作),但实际情况是,在兼容的浏览器使用未注释code,而IE使用'//'标志着code。这里是code:

I have just found something very weird while developing a website. While trying to get a div element to display across the top of the screen, I noticed that I wasn't achieving a desired result in any browser except for old versions of IE. In order to test some different code, instead of deleting the faulty line, I used '//' to comment it out (I'm not really even sure if that works in css) but what happened was, the compatible browsers used the uncommented code, while IE used the code marked by '//'. here is the code:

#ban-menu-div{
position:fixed;top:0;
//position:relative; //<-- IE keeps the banner with rel pos while the other
display:block;       //    browsers used fixed
margin:auto;
padding:0px;
width:100%;
text-align:center;
background:black;
}

所以基本上,它好像//可以用来指导新的浏览器忽略code的具体线路,并指示旧版本的IE使用它?如果这是常见的做法有人请让我知道。它肯定使得旧的浏览器开发了很多的地狱更容易

so basically, it seems as though // can be used to instruct newer browsers to ignore specific lines of code, and instruct older versions of IE to use it? If this is common practice someone please let me know. it sure makes developing for older browsers a hell of a lot easier

推荐答案

// 不是的有效的CSS评论

这是CSS解析正确的浏览器会忽略 //位置,因为 //位置是不是有效的属性名称(细节这里属性 - > 识别S * - > 跟随它通过)。

Browsers that parse CSS properly will ignore //position because //position is not a valid property name (details are here, property -> IDENT S* -> follow it through).

这不仅是因为它众所周知的接受与垃圾prepended物业给他们错误的作品在IE7。

This only works in IE7 due to its well known bug of accepting properties with junk prepended to them.

这不只是 // 的作品。 IE7将在这里有红色文字:

It's not just // that works. IE7 will have red text here:

body {
    !/!*//color: red;
}

这是最典型的利用与 * ,例如 *显示:内联; 作为部分<一个href=\"http://stackoverflow.com/questions/5838454/inline-block-doesnt-work-in-internet-explorer-7-6/5838575#5838575\"><$c$c>display: inline-block的解决方法IE7 。

This is most typically exploited with *, for example *display: inline; as part of the display: inline-block workaround for IE7.

这篇关于做双斜线直接IE使用特定的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆