您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

CSS上一个子选择器:选择特定类的最后一个元素,而不是父内部的最后一个子元素?

CSS上一个子选择器:选择特定类的最后一个元素,而不是父内部的最后一个子元素?

:last-child仅在有问题的元素是容器的最后一个子元素而不是特定类型的元素的最后一个元素时起作用。为此,你想要:last-of-type

根据@BoltClock的注释,这仅检查最后一个article元素,而不检查类为的最后一个元素.comment

body {

  background: black;

}



.comment {

  width: 470px;

  border-bottom: 1px dotted #f0f0f0;

  margin-bottom: 10px;

}



.comment:last-of-type {

  border-bottom: none;

  margin-bottom: 0;

}


<div class="commentList">

  <article class="comment " id="com21"></article>



  <article class="comment " id="com20"></article>



  <article class="comment " id="com19"></article>



  <div class="something"> hello </div>

</div>
CSS 2022/1/1 18:24:23 有323人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶