【发布时间】:2018-01-09 02:26:33
【问题描述】:
我使用 :last-child 选择器,但它不起作用。 示例:
.last {background:blue;border-bottom:1px solid #cccccc;}
.last:last-child {background:red;border-bottom:0px solid #cccccc;}
谢谢大家的回答。
但我还有一个问题。 jsfiddle example 2
.big_box {
background:#eeeeee;
height:500px;
}
.last {
width:90%;
margin:auto;
background: yellow;
border-bottom: 1px solid #cccccc;
}
.last:last-child {
background: red;
border-bottom: 0px solid #cccccc;
}
<div class="big_box">
<div class="other">the other paragraph.</div>
<div class="last">The first paragraph.</div>
<div class="last">The second paragraph.</div>
<div class="last">The third paragraph.</div>
<div class="last">The fourth paragraph.</div>
<div class="other">the other paragraph.</div>
<div class="other">the other paragraph.</div>
<div class="other">the other paragraph.</div>
</div>
【问题讨论】:
-
这只是一个 jsfiddle 怪癖。将您的 div 包装在父 div 中,它工作正常。
-
另一个问题:jsfiddle.net/6dpodkkx/2
-
这里有一个你想要得到的帖子stackoverflow.com/questions/7298057/…我认为这个帖子是重复的
-
@lucianov88 谢谢,但他使用了不同的类型(div 和 article)。
标签: css select css-selectors