我使用:最後一個子選擇器但它不起作用。 例子:CSS:最後一個子選擇器不起作用
.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中,它工作正常。 –
另一個問題:https://jsfiddle.net/6dpodkkx/2/ – user1821062
這裏有一個帖子,你正在嘗試獲取https:// stackoverflow。com/questions/7298057/css-last-child-selector-select-last-element-of-specific-class-not-last-child-i我認爲這篇文章是重複的 – lucianov88