yarek
yarek

Reputation: 12064

css3 pure: how to hover an element outside?

div.test:hover #sendBtn{
    color:red;
}

This works fine is sendBtn is INSIDE the div.test element

But how to achieve this (pure CSS) when it is outside ? ex:

<button id="sendBtn">hello</button>
<div class='test'>div here</div>

Upvotes: 1

Views: 272

Answers (1)

Alex Char
Alex Char

Reputation: 33218

There is no selector for previous element in css but you can change the order of the elements and use adjacent sibling selector:

html

<div class='test'>div here</div>
<button id="sendBtn">hello</button>

css

div.test:hover + #sendBtn {
    color:red;
}

fiddle

Upvotes: 2

Related Questions