开发者

Styling multiple same-level elements on hover

I have HTML markup like this:

<div id="blocks">
    <div class="block"></div>
    <div class="block"></div>
    <div class="block"></div>
</div>

I would like to style all the .bl开发者_StackOverflow社区ock elements that aren't hovered when I hover on a .block. Is there a way that this can be accomplished with just CSS?

Can I do this with a CSS rule similar to .block:hover .block:not(:hover)?


#blocks:hover {
    background-color: blue;
}

.block:hover { 
    background-color: yellow;   
}

See fiddle.

Alternative solution

.block:hover {
    background-color: blue;
}

#blocks:hover .block:not(:hover) { 
    background-color: yellow;   
}

See updated fiddle.


#blocks:hover .block {} for all non hovered elements, but a hovering over the whole #blocks element and #blocks .block:hover {} for the hovered element should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜