문제

Am I able to select .button based on a pseudo-class of .main?

I want div.button to be blue only if div.main is empty (.main:empty). How can I do this using only CSS?

<div class="container">
<div class="header">
    <div class="button">I should have color:blue when .main is empty</div>
</div>
<div class="content">
    <div class="main"></div>
</div>
</div>

(please don't offer to solve using jQuery)

도움이 되었습니까?

해결책

No, there's no way to select a "cousin" with pure CSS.

If #header were after .content, then you could select .button from a pseudo-class of .content -- an "aunt/uncle" -- using the adjacent sibling combinator (+) like this:

.content:hover + #header .button{/* styles */}

But even then, you're not able to select .button from a pseudo-class of .main (the "cousin")

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top