218

这是什么意思?我猜这是一个浏览器黑客,但我无法找到它到底做了什么。

width: 500px\9;

有什么意义\9

4

4 回答 4

301

\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。

于 2011-11-04T04:44:05.123 回答
13

这是 IE9 及以下版本的 css hack

像这样写:

width: 500px\9;

阅读这篇文章http://dimox.net/personal-css-hacks-for-ie6-ie7-ie8/

于 2011-11-04T04:09:05.330 回答
2

在 IE9 中设置 width 属性,您只需添加此 hack。

例如

.align {
    float:left;
    margin:5px;
    background-color:blue;
    width:65px;
    width:\9 !important;
}
于 2013-03-26T13:19:51.193 回答
1

IE9 的 CSS 黑客

/* Hack CSS IE9 */
.csshackie9 {color:#f00\9\0\;}
于 2012-12-05T10:59:47.907 回答