【发布时间】:2011-03-02 23:11:20
【问题描述】:
我通常使用 IE 条件语句并且每个都有一个样式表。这对我来说是一种更简洁的方法。但是由于某些限制,我必须在同一个样式表中破解 ie6 和 7。
我知道它不会验证,但是你如何将 ie6 和 ie7 与同一样式表中的 hack 隔离开来?
【问题讨论】:
标签: css internet-explorer-7 internet-explorer-6
我通常使用 IE 条件语句并且每个都有一个样式表。这对我来说是一种更简洁的方法。但是由于某些限制,我必须在同一个样式表中破解 ie6 和 7。
我知道它不会验证,但是你如何将 ie6 和 ie7 与同一样式表中的 hack 隔离开来?
【问题讨论】:
标签: css internet-explorer-7 internet-explorer-6
浏览器特定的 CSS 黑客综合列表
来源:http://paulirish.com/2009/browser-specific-css-hacks/
/***** Selector Hacks ******/
/* IE6 and below */
* html #uno { color: red }
/* IE7 */
*:first-child+html #dos { color: red }
/* IE7, FF, Saf, Opera */
html>body #tres { color: red }
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }
/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }
/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho { color: red }
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#diez { color: red }
}
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
#veintiseis { color: red }
}
/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece { color: red }
/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red }
/* Everything but IE6-8 */
:root *> #quince { color: red }
/* IE7 */
*+html #dieciocho { color: red }
/* Firefox only. 1+ */
#veinticuatro, x:-moz-any-link { color: red }
/* Firefox 3.0+ */
#veinticinco, x:-moz-any-link, x:default { color: red }
/***** Attribute Hacks ******/
/* IE6 */
#once { _color: blue }
/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }
/* Everything but IE6 */
#diecisiete { color/**/: blue }
/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }
/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }
/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */
确保查看其他解决方案,例如为此目的使用 javascript 库: 我推荐http://www.modernizr.com,它得到了上述黑客保罗爱尔兰列表的同一作者的支持。使用 Modernizr,您可以执行以下操作:
#menu{ .. }
.ie6 #menu{ .. }
.ie7 #menu{ .. }
而不是黑客,更简洁的代码,更容易理解。
另外我建议你查看http://www.quirksmode.org/,它有一个非常完整的支持的浏览器功能和兼容性列表。
【讨论】:
您可以查看this enormous table。
表示可以使用*color: green;。
【讨论】: