Conditionally set style if sibling element exists in PURE CSS
This question already has an answer here:
In general, no. CSS reads forwards/down the DOM - it won't read backwards/up. But with this markup, you could use :not(:last-child)
.firstElement:not(:last-child) {
color: red
}
<div class="wrapper">
<div class="firstElement">target this</div>
<div class="secondElement"></div>
</div>
<div class="wrapper">
<div class="firstElement">not this</div>
</div>
链接地址: http://www.djcxy.com/p/22854.html
上一篇: 如何在div悬停时影响其他元素