Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CSS class/id to change other classes attributes? [closed]

So I want to :hover on an element and I want the hovering to change an attribute of another class. How do I do it? I want to hover on to a button and it to change other div's display to display: block. I use only HTML and CSS.

like image 654
Nikolas Avatar asked Jan 27 '26 02:01

Nikolas


1 Answers

You are limited by css, but there are possibilities with css selectors. I've made you a jsfiddle with a possible solution:

http://jsfiddle.net/6rT3Q/

CSS:

.item1:hover ~ .item3 {
    background-color: red;
}

HTML

<div class="item1">
    Hoverable item
</div>

<div class="item2">
    Dummy item
</div>

<div class="item3">
    Item to change
</div>

Here the ~ tells to look for succeeding elements. If you want the immediate next element you can use +.

More info about selectors:

http://www.w3.org/TR/2001/CR-css3-selectors-20011113/

like image 141
wouthoekstra Avatar answered Jan 29 '26 14:01

wouthoekstra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!