将鼠标悬停在容器div上会分别突出显示嵌套的div

时间:2012-12-01 17:39:57

标签: hover

我正在放置"悬停"课程.one.one :hover)上的功能可将background-color更改为灰色。每当我将鼠标悬停在容器div div上时,我希望它突出显示.two, .three s(.one)。

但是,它的作用是分别悬停在两个嵌套的div.two.three)上。有人可以解释为什么会这样,我要做些什么来突出整个div .one创建一个单一的实心灰色div?

以下是我使用的CSS。



.one {
  width: 200px;
  display: inline-block;
}

.two {
  background-color: rgba(0, 51, 102, 1);
  width: 50px;
  height: 100px;
  float: left;
}

.three {
  background-color: rgba(0, 204, 204, 1);
  width: 150px;
  height: 100px;
  float: right;
}

.one :hover {
  background-color: rgba(153, 153, 153, 1);
}

<div class="one">
  <div class="two">
  </div>
  <div class="three">
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:8)

我认为这个CSS会对你有所帮助:

.one:hover .two, .one:hover .three {
background-color: rgba(153,153,153,1);}