css伪类last,css 伪类:last-child等不起作用(示例代码)

#icons{

border: 1px solid bisque;

height: 250px;

}

#icons .column{//每一列

width:25%;

display: inline-block;float: left;

text-align: center;

}

#icons .column .txt{//每列文字

width:100%;

height: 52px;

margin-top: 134px;

border-right: 2px solid #787b83;//在此处加隔条

}

#icons .column.txt:last-child{

border-right: none;

}

#icons .column .txt p{

width: 160px;

height: 52px;

font-size: 14px;

line-height: 18px;

color: #767777;

margin-left: 25%;

}

html:

打造全新世界观,让你更爱你的生活

丰富多彩的公益活动,发挥新世界的主人公意识

时尚的新理念,超前体验未知的生活

完善的培养机制,培养你全新的世界观

效果如下:

1b5d059162692a5ca081c18fb8bf7507.png

本以为在 `#icons .column .txt` 处加隔条后,想把最后一个竖隔条设为 `border:none;` 没想到如上如所示,全部都不见了。

原来,伪类选择器`:first-child`和`:last-child`是根据父级进行筛选的,`#icons .column .txt:last-child` 的父级是‘.txt`,在该处上的子级只有一个,最后的子级当然也是自己本身,所以要想达到效果,就应该在‘.txt`的父级添加伪类。

#icons .column:last-child .txt{

border-right: none;

}

效果如下:

9b827bbfc3d9a45b2c6eb3c4c9595d26.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值