Short question: Why does the background-color
of .b
does not change when I hover? .a
?
CSS
.a {
color: red;
}
.b {
color: orange;
}
.a:hover .b {
background-color: blue;
}
HTML
<div id="wrap">
<div class="a">AAAA</div>
<div class ="b">BBBB</div>
</div>
Can you not do something like
a:hover + b
? see http://meyerweb.com/eric/articles/webrev/200007a.htmlYou need to have
.a:hover + .b
instead of.a:hover .b
.a:hover .b
would work for a structure likeIf at some point you'll need to have some elements between .a and .b, then you'll need to use
.a:hover ~ .b
, which works for all siblings of.a
coming after it, not just the next one.Demo http://jsfiddle.net/thebabydino/EajKf/
There are two things you can do.
Either change your HTML to make
.b
a child of.a
OR
Change your css to use the adjacent selector
because .b isn't a child of .a, so that selector isn't finding anything. Use javascript to do what you want to do there.
Jquery is a good and easy solution:
html:
script: Put this script into your html if you want. That's all.
no js needed http://jsfiddle.net/2NEgt/3/