我想從 HTML 中的嵌套元素中洗掉一個類。
<div class=sample>
<p>This should have the class as sample</p>
<p>This should not have the class as sample</p>
</div>
在上面的代碼片段中,我不想讓第二個<p>元素擁有類示例。我該怎么做?
uj5u.com熱心網友回復:
您可能想嘗試將:not偽選擇器與:nth-child
.sample > p:not(:nth-child(2)){
color:red;
background:yellow
}
<div class='sample'>
<p>This should have the class as sample</p>
<p>This should not have the class as sample</p>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/399981.html
上一篇:如何使網站上的留言框作業?
