悬停一个元素时如何影响其他元素 [英] How to affect other elements when one element is hovered
本文介绍了悬停一个元素时如何影响其他元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做的是将某个div
悬停时,它将影响另一个div
的属性.
What I want to do is when a certain div
is hovered, it'd affect the properties of another div
.
例如,在此JSFiddle演示中,当您将鼠标悬停在#cube
上时,它会更改background-color
,但是我想要的是当我将鼠标悬停在#container
上时,#cube
会受到影响.
For example, in this JSFiddle demo, when you hover over #cube
it changes the background-color
but what I want is that when I hover over #container
, #cube
is affected.
div {
outline: 1px solid red;
}
#container {
width: 200px;
height: 30px;
}
#cube {
width: 30px;
height: 100%;
background-color: red;
}
#cube:hover {
width: 30px;
height: 100%;
background-color: blue;
}
<div id="container">
<div id="cube">
</div>
</div>
推荐答案
如果多维数据集直接位于容器内部:
If the cube is directly inside the container:
#container:hover > #cube { background-color: yellow; }
如果多维数据集位于容器旁边(在容器关闭标签之后):
If cube is next to (after containers closing tag) the container:
#container:hover + #cube { background-color: yellow; }
如果多维数据集位于容器内的某个位置:
If the cube is somewhere inside the container:
#container:hover #cube { background-color: yellow; }
如果多维数据集是容器的同级物:
If the cube is a sibling of the container:
#container:hover ~ #cube { background-color: yellow; }
这篇关于悬停一个元素时如何影响其他元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文