我想知道您是否可以設定例如 ul 的 li 標簽,僅當另一個標簽跟隨時。(ul 和 li 只是例子)
有沒有給定的方法?還是您必須解決 javascript 的問題?
例如:
<ul>
<li>one</li> <- style this one
<li>two</li> <- also this one
<li>tree</li> <- but not this one, because no other li follows
</ul>
我想你只能通過將最后一個元素的樣式覆寫回默認樣式來做到這一點
例如:
li {
background: #000000f0;
}
li:last-child {
background: none;
}
uj5u.com熱心網友回復:
你的猜測是正確的,使用 li:last-child 就可以了。或者您可以通過以下方式使您的生活復雜化:
li::not(:last-child)
uj5u.com熱心網友回復:
您不必重新設定最后一個元素的樣式,這很復雜,需要知道樣式是什么并重復它。
您可以使用非偽類
li:not(:last-child) {
background: #000000f0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/460401.html
