div id='b'当我将鼠标悬停在 上时,我想使用 CSS 来显示div id='a',但我不知道该怎么做,因为它在div 'a'另一个不在的内部。divdiv 'b'
<div id='content'>
<div id='a'>
Hover me
</div>
</div>
<div id='b'>
Show me
</div>
我们可以像这样在悬停时显示相同的标签 div
<style>
#b {
display: none;
}
#content:hover~#b{
display: block;
}
</style>
确实可以使用以下代码
<div href="#" id='a'>
Hover me
</div>
<div id='b'>
Show me
</div>
和CSS
#a {
display: block;
}
#a:hover + #b {
display:block;
}
#b {
display:none;
}
现在通过将鼠标悬停在元素#a 上显示元素#b。
您可以为此使用斧头选择器。
有两种方法:
<)#a:hover < #content + #b
此ax样式规则将选择#b,它是 的直接兄弟,它是具有状态#content的直接父级。#a:hover
div {
display: inline-block;
margin: 30px;
font-weight: bold;
}
#content {
width: 160px;
height: 160px;
background-color: rgb(255, 0, 0);
}
#a, #b {
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
}
#a {
color: rgb(255, 0, 0);
background-color: rgb(255, 255, 0);
cursor: pointer;
}
#b {
display: none;
color: rgb(255, 255, 255);
background-color: rgb(0, 0, 255);
}
#a:hover < #content + #b {
display: inline-block;
}
<div id="content">
<div id="a">Hover me</div>
</div>
<div id="b">Show me</div>
<script src="https://rouninmedia.github.io/axe/axe.js"></script>
\)#a:hover \ #b
此ax样式规则将选择#b,它存在于#a具有:hover状态的同一文档中。
div {
display: inline-block;
margin: 30px;
font-weight: bold;
}
#content {
width: 160px;
height: 160px;
background-color: rgb(255, 0, 0);
}
#a, #b {
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
}
#a {
color: rgb(255, 0, 0);
background-color: rgb(255, 255, 0);
cursor: pointer;
}
#b {
display: none;
color: rgb(255, 255, 255);
background-color: rgb(0, 0, 255);
}
#a:hover \ #b {
display: inline-block;
}
<div id="content">
<div id="a">Hover me</div>
</div>
<div id="b">Show me</div>
<script src="https://rouninmedia.github.io/axe/axe.js"></script>