IE6、IE7不支持 first-child 属性

本文介绍了如何在IE6和IE7中通过CSS代码实现first-child属性的功能,包括使用表达式来判断元素是否为首个子元素,并提供了具体的代码解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://www.aoao.org.cn/blog/2007/03/first-child/


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就是那么强大!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值