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

前端之家收集整理的这篇文章主要介绍了将鼠标悬停在容器div上会单独突出显示嵌套的div前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在类.one(.one:hover)上放置了一个“悬停”功能,将背景颜色更改为灰色.每当我将鼠标悬停在容器上时,我都希望它突出显示两个div(.two,.three).

但是,它的作用是分别悬停在两个嵌套的div(.two,.three)上.有人可以解释为什么会这样,我要做些什么来突出整个div.创建一个单一的实心灰色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,1);
  width: 150px;
  height: 100px;
  float: right;
}

.one :hover {
  background-color: rgba(153,153,1);
}
<div class="one">
  <div class="two">
  </div>
  <div class="three">
  </div>
</div>

解决方法

我认为这个CSS会帮助你:
.one:hover .two,.one:hover .three {
background-color: rgba(153,1);}
原文链接:https://www.f2er.com/css/213962.html

猜你在找的CSS相关文章