Question

Trying to select sibling elements on hover one element. Is there any way to select the elements up the dom tree also? I'm looking for a CSS solution only.

<div id="a">Div A</div>
<div id="b">Div B</div>
<div id="c">Div C</div>
<div id="d">Div D</div>

<style>

#a:hover ~ #b,
#a:hover ~ #c,
#a:hover ~ #d{
    background: #ccc
}

#b:hover ~ #a,
#b:hover ~ #c,
#b:hover ~ #d{
    background: #ccc
}

#c:hover ~ #a,
#c:hover ~ #b,
#c:hover ~ #d{
    background: #ccc
}

#d:hover ~ #a,
#d:hover ~ #b,
#d:hover ~ #c{
    background: #ccc
}

</style>

http://jsfiddle.net/u7tYE/3381/

Était-ce utile?

La solution

I you use a parent container, and i guess it has, you can get something really close with little CSS. http://jsfiddle.net/u7tYE/3382/

#all:hover div {
    background:#ccc;
}
#all:hover div:hover {
    background:none;
}
<div id="all">
    <div id="a">Div A</div>
    <div id="b">Div B</div>
    <div id="c">Div C</div>
    <div id="d">Div D</div>
</div>

Autres conseils

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top