:last-child 怎么无效

冬天太冷 2017-11-24 10:07:29
html代码是这样的:

css 是这样写的:
.other-item{
margin:25px 15px 15px 20px;
float: left;
border-right:1px solid #ddd;
height:68%;
text-align: left;
padding-right:15px;
}
.other-item:last-child{
border-right:none;
padding-right:0;
color:red;
}
无效果
...全文
1793 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_41895263 2019-09-23
  • 打赏
  • 举报
回复 1
使用 :last-child 伪类时要保证后面没有兄弟元素节点。 解决方法:把<div class="button"><div/>去掉。 或者把<div class="button"><div/>移出<div class=""other-content clearfix><div/>,不要放在<div class=""other-content clearfix><div/>里面。
qq_26610735 2017-11-24
  • 打赏
  • 举报
回复
你可以用nth-child写的
天际的海浪 2017-11-24
  • 打赏
  • 举报
回复
你可以用 last-of-type 匹配同样标签名中的最后一个同级兄弟元素 但要注意last-of-type 是只能以标签名来分组,不能用class来分组
天际的海浪 2017-11-24
  • 打赏
  • 举报
回复
last-child 是匹配父元素的最后一个子元素。你的所有.other-item元素都不是父元素的最后一个子元素。当然都不匹配。(你的父元素的最后一个子元素是<div class="button"></div> )
public_TIM 2017-11-24
  • 打赏
  • 举报
回复
:last-child只匹配一个元素,而此选择符将为每个父元素匹配一个子元素,你的 .other-item的div里面还有子元素吗?

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧