1
<div class="main">
    <div class="content">
        <div class="content_hide">
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        </div>
    </div>
    <div class="sidebar">
        <div class="single_sidebar">
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        </div>
    </div>
</div>

This is my HTML code. When I hover single_sidebar element, I want style content_hide div. something like

.single_sidebar:hover @@content_hide {background:red}

How can I select content_hide div by CSS when I hover single_sidebar?

4

1 回答 1

3

目前在 CSS 中没有办法这样做。也许只在CSS4 中带有!.

您将不得不合并 JavaScript。

举个例子,在 jQuery 中:

$(".single_sidebar").on("mouseenter mouseleave", function(event) {
  $(this).closest(".main").find(".content_hide").toggleClass("someStyleClass");
});
于 2013-08-06T09:05:04.580 回答