css:当另一个div悬停时显示div [英] css: show div when another div is hover
本文介绍了css:当另一个div悬停时显示div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个div。 div A和div B.如果div A悬停,那么我需要显示div B.这可以用纯CSS实现吗?或者如果我在查询,我怎么去这个基础上假设我们不能使用id这两个div。
I've got 2 divs. Div A and Div B. If Div A is hovered, then I need show Div B. Can this be achieved with pure css only? Or if I do it in query, how do i go about with this base on the assumption that we cannot use id for these 2 divs.
谢谢
/ code>:
http://jsfiddle.net/4p8CM / 1 /
#container > div {
display: none
}
#container > div:first-child {
display: block
}
#container > div:hover + div {
display: block
}
<div id="container">
<div>A</div>
<div>B</div>
</div>
:first-child
解决你设置的这个限制:
The :first-child
stuff is to work around this limitation that you set:
基于假设我们不能
对这两个div使用id
base on the assumption that we cannot use id for these 2 divs
如果您希望第二个 div
当您将鼠标悬停在其上时,您可以尝试以下操作:
If you want the second div
to stay visible when you hover over it, try this:
#container > div {
display: none
}
#container > div:first-child {
display: block
}
#container:hover > div {
display: block
}
这篇关于css:当另一个div悬停时显示div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文