IE6/IE7不支持first-child的解决办法

来自:互联网
时间:2018-08-14
阅读:

IE6、IE7不支持 first-child 属性,不过可以用其他办法替代。

#sidebar li:first-child{
border-top-style:none;
}
#sidebar li{
border-top-width:1px;
border-top-style:solid;
border-color:#DAD3D0;
*border-top-style:expression(this.previousSibling==null?"none":"solid");
}

代码解析

*border-top-style:expression(this.previousSibling==null?’none’:"solid’);

只有IE6和IE7能识别此行代码,第一个值’none’就是first-child的值,第二个值’solid’则是其他元素的值。

last-child原理相同,代码如下

#sidebar li:last-child{
border-bottom-style:none;
}
#sidebar li{
border-bottom-width:1px;
border-bottom-style:solid;
border-color:#DAD3D0;
*border-bottom-style:expression(this.nextSibling==null?"none":"solid");
}

现在,IE6和IE7是不是相当于实现了first-child的功能了,CSS就是那么强大!

返回顶部
顶部