当鼠标位于不同div上方时如何显示其他div?
我想当光标悬停在 .a div 上时显示 .b div。可以做吗? 我知道当我将 .b 放入 .a div 时可以做到这一点,但我宁愿不这样做。
<html>
<head>
<title>
How to
</title>
<style>
.b{
background-color: royalblue;
display:none;
}
.a:hover > b{
display: block;
}
.a:hover{
background-color: pink;
}
.a{
background-color: lawngreen;
}
</style>
</head>
<body>
<div class="a" style="width: 200px; height: 200px; "></div>
<div class="b" style="width: 100px; height: 100px;"></div>
</body>
i want to display .b div when cursor is hover on .a div. Is it possible to do?
I know that its possible to do when i put .b into .a div, but i would rather not to do it.
<html>
<head>
<title>
How to
</title>
<style>
.b{
background-color: royalblue;
display:none;
}
.a:hover > b{
display: block;
}
.a:hover{
background-color: pink;
}
.a{
background-color: lawngreen;
}
</style>
</head>
<body>
<div class="a" style="width: 200px; height: 200px; "></div>
<div class="b" style="width: 100px; height: 100px;"></div>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 css
+
加选择器重要通知:
仅当
a
位于b
旁边,并且a
之间有(例如)c
时,此功能才有效和c
,它不会工作You could you use the css
+
plus selectorImportant notice:
This will only work if
a
is next tob
, if there is (for example) ac
betweena
andc
, it will not work是的,您可以使用 相邻同级选择器(+)
这是一个 演示
这里唯一需要注意的是样式将被应用到下一个元素。
您还可以检查 通用兄弟选择器(~)
Yes, you can do it by using adjacent sibling selector (+)
Here is a demostration
Only catch here is that style will be applied to the next element.
You can also check General sibling selector(~)