CSS:最后一个子选择器不起作用?
<div class="commentList">
<article class="comment " id="com21"></article>
<article class="comment " id="com20"></article>
<article class="comment " id="com19"></article>
</div>
知道为什么以下最后一个子选择器对我不起作用吗?
.comment {
width:470px;
border-bottom:1px dotted #f0f0f0;
margin-bottom:10px;
}
.comment:last-child {
border-bottom:none;
margin-bottom:0;
}
因此,在这种情况下,#com19
不应在底部有边框和边距。 我在这里做错了什么?
谢谢
<div class="commentList">
<article class="comment " id="com21"></article>
<article class="comment " id="com20"></article>
<article class="comment " id="com19"></article>
</div>
Any idea why the following last-child selector won't work for me?
.comment {
width:470px;
border-bottom:1px dotted #f0f0f0;
margin-bottom:10px;
}
.comment:last-child {
border-bottom:none;
margin-bottom:0;
}
So in this case #com19
shouldn't have a border and a margin at the bottom.
What am I doing wrong here?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来一切都是正确的 - 我已经创建了 jsfiddle 与最后一个孩子
问题出在其他地方 - 是什么“$border”的值? (是php变量吗?)
为了确保您的语句将被使用,您可以添加 !important
It looks like everything is correct - i have created jsfiddle with last-child
The problem is somewhere else - what is the value of "$border" ? (is it php variable?)
To be sure that your statements will be used, you can add !important
您使用什么浏览器?
IE<9 不会应用
:last-child
选择器样式。What browser are you using?
IE<9 will not apply the
:last-child
selector styles.我尝试在 Codepen 中复制它并遇到类似的问题。 https://codepen.io/Ukmasmu/pen/PoZOLNz
可能有一个不可见的元素结束。看起来它可能是像脚本标签这样的元素或其他一些不可见的 NodeElement。检查 DevTools 是否有这种可能性。
为了安全起见,您可以使用 :last-of-type 伪元素!
I tried to replicate it in Codepen and had a similar Issue. https://codepen.io/Ukmasmu/pen/PoZOLNz
Probably there is an invisible element at the end. It seems that it may be an Element like a script tag or some other NodeElement that's not visible. Check the DevTools for that possibility.
You could use the :last-of-type pseudo element to be safe!