nth-child在IE7/IE8中不起作用

Poi*_*dow 6 css internet-explorer css-selectors css3

我无法让:nth-child选择器与IE7/8一起使用.

这是我的代码的一个工作示例(在Chrome中有效)

下面是我使用的CSS和HTML:

CSS:

#price-list {
    width:98%;
    padding:1%;
    border:white 1px solid;
    margin:0 auto;
    overflow:hidden;
}        
#price-list h4 {
    padding-top:20px; 
    font-weight:400;  
    padding-bottom:5px;
}        
#price-list ul { 
    width:100%; 
    margin-bottom:10px; 
    overflow:hidden; 
}      
#price-list li{
    line-height:1.5em;
    border-bottom:1px  dashed #C9F;
    float:left;
    display:inline;
    padding-top:5px; 
    padding-bottom:5px;
    text-align:center;          
}        
#price-list li strong { 
    color:#C9F; 
    font-weight:normal;
}        
#double-taxi li:nth-child(odd) { 
    width:80%;
    text-align:left; 
}
#double-taxi li:nth-child(even) { 
    width:20%;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="price-list">
   <ul id="double-taxi">            
      <li><h4>North Goa</h4><strong>(Distance kms)</strong></li><li><h4>Non A/C</h4>Rs <strong>(UK &pound;)</strong></li>
      <li>Aldona <strong>(10 kms)</strong></li><li>250 Rs <strong> (&pound;3)</strong></li>
      <li>Asnora <strong>(15 kms)</strong></li><li>250 Rs <strong> (&pound;3)</strong></li>
      <li>Bicholim <strong>(21 kms)</strong></li><li>420 Rs <strong> (&pound;5)</strong></li>
      <li>Camurlim <strong>(10 kms)</strong></li><li>250 Rs <strong> (&pound;3)</strong></li>
      <li>Colvale <strong>(10 kms)</strong></li><li>250 Rs <strong> (&pound;3)</strong></li>
   </ul>
     We DO NOT provide a taxi service. The Exchange Rate used to calculate UKP was 80Rs to the UKP and was rounded  up to whole pound.
</div>
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

dsg*_*fin 9

这是因为:nth-child IE7/IE8不支持.

这个问题的一个解决方案是使用 Selectivizr.

"Selectivizr是一个JavaScript实用程序,可以在Internet Explorer 6-8中模拟CSS3伪类和属性选择器."

你需要做的就是包括Selectivizr脚本,如果你还没有使用它,决定你想使用哪个JavaScript库(jQuery,Mootools等),你将获得:nth-child选择器的支持(以及其他各种选择) IE6到IE8中的伪选择器/属性选择器.

编辑:

在回复您的评论时,这是一个快速教程,向您展示如何设置和使用Selectivizr.


Khi*_*eeb 7

以下示例可能对您有所帮助

//For first child
// equivalent to li:nth-child(1)
li:first-child a {
    border-top: 5px solid red;
}

//For second child
// equivalent to li:nth-child(2)
li:first-child + li a {
    border-top: 5px solid blue;
}

//For third child
// equivalent to li:nth-child(3)
 li:first-child + li + li a {
    border-top: 5px solid green;
}?
Run Code Online (Sandbox Code Playgroud)

  • 你能为你提供的css添加一些解释吗? (2认同)
  • 它值得了解,但它没有解决问题中的"nth-child(odd)"等情况."first-child"和"+"选择器在IE7中也有严重错误,所以作为替代解决方案并不是那么好. (2认同)