简体   繁体   English

悬停另一个div时隐藏div

[英]Hide div when hovering another div

so i have a few divs inside divs like this: 所以我在div内有几个div像这样:

  <div class="flip-container">
        <div class="flipper">
            <a href="#" data-reveal-id="pc1">
                <div class="inner" style="background-color:#ea6524;">
                    <p class="text">title</p>
                    <img src="1.png" class="img" />
                </div>
            </a>
        </div>
   </div>

DESCRIPTION: now the flip-container and the flipper are used because when i hover this div i have a css transition triggered which flips the div. 说明:现在使用了翻转容器和翻转器,因为当我将鼠标悬停在此div上时,会触发一个css转换来翻转div。 the href simply allows to open a div with a description when the inner div is clicked the inner div is a square with inside a text and an image. 当单击内部div时,href只是允许打开一个带说明的div。内部div是一个带有文本和图像的正方形。

WHAT I WANT TO DO: i would like to hide the text "title" and the img "1.png" when i hover the flip-container. 我想做什么:当我将鼠标悬停在翻转式容器上时,我想隐藏文本“ title”和img“ 1.png”。

how can i do this? 我怎样才能做到这一点?

i tried to add display:hidden to the class text but it works only when i hover the actual text and not when i hover the flip-container background. 我试图将display:hidden添加到类文本中,但仅当我将鼠标悬停在实际文本上时才起作用,而当我将翻转容器背景悬停时则不起作用。

thanks for the help 谢谢您的帮助

i would prefer a pure css solution if possible, if not also a javascript solution could do. 如果可能的话,我宁愿使用纯CSS解决方案,如果不能,那么javascript解决方案也可以。

This should do the trick: 这应该可以解决问题:

.flip-container:hover .text, .flip-container:hover img {
    display: none;
}

Alternatively, you could use visibility: hidden as this will keep the elements in the document flow, rather than removing them all together. 或者,您可以使用visibility: hidden因为这将使文档中的元素保持流动,而不是一起删除它们。

OP, OP,

In this case, I'd suggest visibility:hidden over display:none; 在这种情况下,我建议您进行visibility:hiddendisplay:none; . Here's a fiddle with this approach: http://jsfiddle.net/wEr3T/1/ . 这是使用这种方法的小提琴: http : //jsfiddle.net/wEr3T/1/

In short, visibility:hidden will literally just hide the element(s)—still taking up the space it did before, thus not affecting the layout. 简而言之,“ visibility:hidden实际上只会隐藏元素,而仍会占用之前的空间,因此不会影响布局。

In contrast, display:none; 相反, display:none; causes it not to be rendered, thus the space it had previously occupied is now unaccounted for. 导致无法渲染,因此以前占用的空间现在无法计算。 As such, hovering to show/hide elements that have been set to display:none will likely cause some undesired flickering. 因此,将鼠标悬停在显示/隐藏已设置为display:none元素上可能会导致一些不希望的闪烁。

hiding the text and the image when hovering #flip-container by setting display: none may cause flashing and change in layout of the parent container. 通过设置display: none鼠标悬停在#flip-container时隐藏文本和图像display: none可能会导致闪烁并更改父容器的布局。 so instead make them transparent by set visibility: hidden . 因此,而是通过设置visibility: hidden使它们透明。

.flip-container:hover img {
visibility:hidden
}
.flip-container:hover .text {
visibility:hidden
}

i have created jsFiddle for you. 我已经为您创建了jsFiddle

Try this... 尝试这个...

 .flip-container:hover .text, .flip-container:hover img { visibility: hidden; } 
  <div class="flip-container"> <div class="flipper"> <a href="#" data-reveal-id="pc1"> <div class="inner" style="background-color:yellow;"> <p class="text" style="color:red">title</p> <img src="//placehold.it/100x100" class="img" /> </div> </a> </div> </div> 

展示<div>当悬停在另一个 div 及其子项上时</div><div id="text_translate"><p>我有一个 HTML div,里面有孩子。 我有一个附加到 div 的 jQuery 鼠标悬停事件。 鼠标悬停时,我显示另一个 div,鼠标悬停时,我隐藏它。</p><p> 但是,当我将鼠标悬停在“premiumlink”div 上时,一切正常,但是当我将鼠标移到 div 的一个子项上时,有条件显示的 div 会隐藏,但随后 jQuery 发现父 div 仍在悬停,所以它再次显示它。 然后,如果我将 cursor 移回父 div,则该 div 被隐藏然后再次显示。</p><p> 我怎样才能让鼠标悬停和鼠标悬停适用于所有孩子,而不是这个跳跃的 state?</p><p> 这是我的 HTML</p><pre> &lt;div class="platinumlevel" id="premiumlink"&gt; &lt;h1&gt; &lt;img src="~/Content/Images/colorworld.png" alt="Logo" class="eventimage" /&gt; &lt;a href="@Url.Action("Exhibitor1Attendee", "Home")" class="landing"&gt;Company Name&lt;/a&gt; &lt;/h1&gt; &lt;div id="demopreview" style="display: none;"&gt; I should be displayed when "premiumlink" and all it's children are mouseovered &lt;/div&gt; &lt;/div&gt;</pre><p> JS</p><pre> $("#premiumlink").mouseover(function () { $('#demopreview').show(1000); }).mouseout(function () { $('#demopreview').hide(1000); });</pre></div> - Display <div> when hovering over another div and its children

暂无
暂无

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

相关问题 悬停在另一个div上时显示和隐藏按钮 - Show and hide buttons when hovering on another div 使用jQuery将另一个div悬停时移动div - Move div when hovering another div with jquery 将鼠标悬停在另一个div上时更改Div属性? - Change Div Property when hovering on another div? 悬停时显示div,不显示时隐藏 - Show div when hovering, hide when not 如何在悬浮图像或文本时隐藏一个div并隐藏另一个div? - how to hide one div and hide another on hovering image or text? 将鼠标悬停在另一个div上时,将其定位到特定div - Target a specific div when hovering over another 悬停另一个时更改div的CSS(JQuery) - Change CSS of a div when hovering another (JQuery) 将鼠标悬停在div上时,如何将一个类添加到另一个div? - When hovering over a div, how to add a class to another div? 展示<div>当悬停在另一个 div 及其子项上时</div><div id="text_translate"><p>我有一个 HTML div,里面有孩子。 我有一个附加到 div 的 jQuery 鼠标悬停事件。 鼠标悬停时,我显示另一个 div,鼠标悬停时,我隐藏它。</p><p> 但是,当我将鼠标悬停在“premiumlink”div 上时,一切正常,但是当我将鼠标移到 div 的一个子项上时,有条件显示的 div 会隐藏,但随后 jQuery 发现父 div 仍在悬停,所以它再次显示它。 然后,如果我将 cursor 移回父 div,则该 div 被隐藏然后再次显示。</p><p> 我怎样才能让鼠标悬停和鼠标悬停适用于所有孩子,而不是这个跳跃的 state?</p><p> 这是我的 HTML</p><pre> &lt;div class="platinumlevel" id="premiumlink"&gt; &lt;h1&gt; &lt;img src="~/Content/Images/colorworld.png" alt="Logo" class="eventimage" /&gt; &lt;a href="@Url.Action("Exhibitor1Attendee", "Home")" class="landing"&gt;Company Name&lt;/a&gt; &lt;/h1&gt; &lt;div id="demopreview" style="display: none;"&gt; I should be displayed when "premiumlink" and all it's children are mouseovered &lt;/div&gt; &lt;/div&gt;</pre><p> JS</p><pre> $("#premiumlink").mouseover(function () { $('#demopreview').show(1000); }).mouseout(function () { $('#demopreview').hide(1000); });</pre></div> - Display <div> when hovering over another div and its children 悬停另一个div时如何保持div可见 - How to keep div visible when hovering another div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM