简体   繁体   English

将鼠标悬停在其上时显示隐藏的div I

[英]show hidden div I when hover over it

I have a hidden div, as in it has the property: display:none . 我有一个隐藏的div,因为它具有属性: display:none I need to show it when I hover it and not another element, which means, I want it to appear, or display:block as soon as I hover over IT. 当我将其悬停而不是其他元素时,我需要显示它,这意味着我希望它出现在鼠标悬停在IT上时,或者display:block I have found questions where they are working on the case where you show the div when you hover on the div containing that hidden div: Show hidden div on hover 我发现了在将鼠标悬停在包含该隐藏div的div时显示div的情况下,它们在起作用的问题: 在悬停时显示隐藏的div

HTML HTML

<a href="#" id="case1"><div>my hidden div</div></a>

CSS CSS

#case1{
    display: none;
}

If you could give me a bonus and answer this related question as well i'd be thankful: 如果您能给我奖金并回答这个相关问题,我将不胜感激:

I have hidden div, that I want to show when I hover over a seperate a href link. 我有隐藏的div,当我将鼠标悬停在单独a href链接上时要显示。 but for some reason it is not working: 但由于某种原因它不起作用:

HTML HTML

<nav>
        <ul id="pics">
          <li><a href="#"><img src="img1"></a></li>
          <!--other <li>-->
        </ul>
        <ul id="menu">
          <li><a href="#">show img1</a></li>
          <!--other <li>-->
        </ul>
</nav>

I want to hide img1 and show it when I hover on the a href that says show img1. 当我将鼠标悬停在显示show img1 a href上时,我想隐藏img1并显示它。

All help is really appreciated. 非常感谢所有帮助。 Thanks 谢谢

The display: none property removes the element from the flow. display: none属性将从流中删除元素。 In other words, it's not there at all so you can't click it, hover over it, etc. 换句话说,它根本不存在,因此您无法单击它,将鼠标悬停在上面等等。

If you want the element to remain in the flow (ie "take up space") but just be invisible, you can use visibility or opacity . 如果您希望元素保留在流程中(即“占用空间”)但只是不可见,则可以使用visibilityopacity

Regarding the first question, well, you cannot hover over an element which is not displayed. 关于第一个问题,很好,您不能将鼠标悬停在未显示的元素上。 (ie display: none ) (即display: none

You may try to set its opacity or visibility to 0 , but not displaying it at all makes it non-hoverable. 您可以尝试将其opacityvisibility设置为0 ,但是根本不显示会使它不可悬停。

You can also combine the opacity: 0 effect with height: 0px (or any other small value), so as to make it smaller and invisible at the same time. 您还可以将opacity: 0效果与height: 0px (或任何其他小值)结合使用,以使其同时变小和不可见。

Try using this CSS, the visibility property keeps an elements space while making it invisible, so you can still hover over it! 尝试使用此CSS,visible属性在保持元素空间的同时使其不可见,因此您仍然可以将其悬停在上面!

#case1 {
    visibility: hidden;
}

#case1:hover {
    visibility: visible;
}

For the second part: 对于第二部分:

$("#menu a").hover(function(){
    $("#pics img").show();
},function(){
    $("#pics img").hide();
});

Demo: http://jsfiddle.net/KYXL4/ 演示: http//jsfiddle.net/KYXL4/

You can't hover a hidden element but since it's a child of an anchor you can hover the anchor. 您无法悬停隐藏元素,但是由于它是锚的子代,因此您可以悬停锚。

#case1:hover div {display: block;}

Without using an id... 不使用ID ...

a:hover div {display: block;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM