这是什么意思?我猜这是一个浏览器黑客,但我无法找到它到底做了什么。
width: 500px\9;
有什么意义\9
?
\9
是特定于 Internet Explorer 7、8 和 9 的“CSS hack”。
这仅仅意味着以 a\9;
代替 the结尾的特定 CSS 行;
仅在 IE 7、8 和 9 中有效。
在你的例子中,
width: 500px\9;
表示width: 500px;
只有在使用 IE 7、8 和 9 时才会应用 500 像素的宽度(与 相同的结果)。
所有其他浏览器将完全忽略width: 500px\9;
,因此根本不适width: 500px;
用于该元素。
如果你的 CSS 看起来像这样......
#myElement {
width: 300px;
width: 500px\9;
}
结果#myElement
在 IE 7、8 和 9 中为 500 像素宽,而在所有其他浏览器中#myElement
为 300 像素宽。
编辑:
这个答案写于 2011 年。现在应该注意的是,这个 hack 也适用于 IE 10。
这是 IE9 及以下版本的 css hack
像这样写:
width: 500px\9;
在 IE9 中设置 width 属性,您只需添加此 hack。
例如
.align {
float:left;
margin:5px;
background-color:blue;
width:65px;
width:\9 !important;
}
IE9 的 CSS 黑客
/* Hack CSS IE9 */
.csshackie9 {color:#f00\9\0\;}