社区
CSS
帖子详情
: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;
}
无效果
...全文
1894
5
打赏
收藏
:last-child 怎么无效
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; } 无效果
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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里面还有子元素吗?
:last-of-type , :last-
child
无效
的问题
:last-of-type
无效
碰到的问题: <style> .c:last-of-type{ background:red; } </style> eg 1: <p>这是第一个段落。</p> <p class='c'>这是第二个段落。</p> <p class='c'>这是第三个段落。</p> ...
last-
child
,:nth-
child
()
无效
当使用类名设置的时候 ,会出现 last-
child
,:nth-
child
()
无效
的情况,可以使用标签名来设置,就可以了 具体原因不大清楚,哪位大佬知道的话,请赐教。 button:last-
child
{ margin-left: 16px; } //生效 .ant-btn:last-
child
{ margin-left: 16px; } //不生效 ...
css -- 为什么:last-
child
无效
?
在产品需求中,总有对第一个或者最后一个同类元素进行特殊的样式处理。 如果使用js来判断哪个是第一个、最后一个也并不是不可以。 但是,完全属于css的管理范围为什么要去使用js呢? css选择器出场! 下面仅展示:last-
child
效果 1.期望效果 代码展示: <template> <div class="root-container"> <div class="father"> <div class="
child
" v-for="item
:last-
child
无效
使用 :last-
child
伪类时要保证后面没有兄弟元素节点!!!!!!!
解决css中E:first-
child
,E:last-
child
,nth-
child
()
无效
的问题
总结原因:nth-
child
()它的范围是在E(这里是li)的所有兄弟sibilings中,故li:nth-
child
(1)是指的第一个li,而在原来的ul:nth-
child
(1)是指整个ul,包括了里面所有的li。情况:h1排在第2位,改变了颜色,而第3位的h2不变。注意:h3:last-
child
此时
无效
。目的:想给ul中第一个li设置颜色。更改标签,第3位是h2。
CSS
61,119
社区成员
60,701
社区内容
发帖
与我相关
我的任务
CSS
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
复制链接
扫一扫
分享
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章