如何匹配第一個div,除非第一個div是div.error
?選擇第一種不包括div.class
<div>
<div class="error">
<p>Error 1.</p>
<p>Error 2.</p>
</div>
<div> <!--I want to tag this-->
Content
</div>
<div>
Content
</div>
<div>
Content
</div>
</div>
我嘗試:
div > div:first-of-type:not(.error) {color:red}
div > div[class]:not(.error):first-of-type {color:red}
的div.error可能出現與否(取決於是否有錯誤或沒有),所以我不能使用類似nth-of-type(2)
我不清楚自己想做的事,但它聽起來像JavaScript可以解決你的問題 –
我想,以配合在div評論「我想標記這個」 – Arkana