【问题标题】:combining IE6 and IE7 css hacks in same stylesheet在同一个样式表中结合 IE6 和 IE7 css hack
【发布时间】:2011-03-02 23:11:20
【问题描述】:

我通常使用 IE 条件语句并且每个都有一个样式表。这对我来说是一种更简洁的方法。但是由于某些限制,我必须在同一个样式表中破解 ie6 和 7。

我知道它不会验证,但是你如何将 ie6 和 ie7 与同一样式表中的 hack 隔离开来?

【问题讨论】:

    标签: css internet-explorer-7 internet-explorer-6


    【解决方案1】:

    浏览器特定的 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/,它有一个非常完整的支持的浏览器功能和兼容性列表。

    【讨论】:

    • Modernizr 是开源的吗?用于专业网站是否安全?同样对于属性黑客,语法是什么?
    • @testndtv 如果您打开链接是它说的第一件事,Modernizar 是一个“开源库”。是的,它对专业发展是安全的,因为它是为此而设计的。一些最优秀的人在那里工作。如果您想了解更多信息,请打开链接并转到文档。
    【解决方案2】:

    您可以查看this enormous table
    表示可以使用*color: green;

    【讨论】:

      猜你喜欢
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      • 2011-02-14
      • 1970-01-01
      • 2010-10-11
      相关资源
      最近更新 更多