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

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

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

下面是我使用的CSS.

  1. .one {
  2. width: 200px;
  3. display: inline-block;
  4. }
  5.  
  6. .two {
  7. background-color: rgba(0,51,102,1);
  8. width: 50px;
  9. height: 100px;
  10. float: left;
  11. }
  12.  
  13. .three {
  14. background-color: rgba(0,204,1);
  15. width: 150px;
  16. height: 100px;
  17. float: right;
  18. }
  19.  
  20. .one :hover {
  21. background-color: rgba(153,153,1);
  22. }
  1. <div class="one">
  2. <div class="two">
  3. </div>
  4. <div class="three">
  5. </div>
  6. </div>

解决方法

我认为这个CSS会帮助你:
  1. .one:hover .two,.one:hover .three {
  2. background-color: rgba(153,1);}

猜你在找的CSS相关文章