Html 将 div 悬停在另一个 div 上时出现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19062120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:53:04  来源:igfitidea点击:

Make a div appear on hover over another div

csshtmlhover

提问by tuckerchapin

I am trying to have it so that a little colored box comes up when you hover over an image.I have recreated the scenario here: http://jsfiddle.net/UaXUS/

我正在尝试使用它,以便当您将鼠标悬停在图像上时会出现一个彩色小框。我在这里重新创建了场景:http: //jsfiddle.net/UaXUS/

The div shows up properly when I remove the visibility:hiddenattribute, but not when I try to use the hover part. Any suggestions as to how to fix this? I have also tried display:nonegoing to display:inlineor display:block, but no luck

当我删除visibility:hidden属性时,div 会正确显示,但当我尝试使用悬停部分时不会。有关如何解决此问题的任何建议?我也试display:none过去display:inlineor display:block,但没有运气

回答by Davide Icardi

Replace

代替

#content:hover + #hoverbar{
    visibility:visible;
}

with

#content:hover > #hoverbar{
    visibility:visible;
}

or

或者

#content:hover #hoverbar{
    visibility:visible;
}

The plus sign '+' is for siblings. In your case the div is nested.

加号“+”代表兄弟姐妹。在您的情况下,div 是嵌套的。

Here the updated jsfiddle

这里更新了 jsfiddle