双正斜杠直接 IE 使用特定的 css 吗? [英] Do double forward slashes direct IE to use specific css?

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

问题描述

我刚刚在开发网站时发现了一些非常奇怪的东西.在尝试让 div 元素显示在屏幕顶部时,我注意到除了旧版本的 IE 之外,我在任何浏览器中都没有达到预期的结果.为了测试一些不同的代码,而不是删除错误的行,我使用//"将其注释掉(我什至不确定这是否适用于 css)但发生的情况是,兼容的浏览器使用了未注释的代码,而 IE 使用了标有//"的代码.这是代码:

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;
}

所以基本上,似乎//可以用来指示较新的浏览器忽略特定的代码行,并指示旧版本的 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 的浏览器将忽略 //position 因为 //position 不是有效的属性名称(详细信息是 这里property -> IDENT 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).

这仅在 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;
}

这通常与 * 一起被利用,例如 *display: inline; 作为 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天全站免登陆