我在类.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);}