简体   繁体   English

[HTML] [CSS]悬停显示div,定位

[英][HTML][CSS] Display div on hover, targeted

When displaying a div on hover, how can you target a specific div? 在悬停显示div时,如何定位特定的div? I need to display a hidden div from a link is on top of the page, and I can't figure out how. 我需要在页面顶部的链接中显示隐藏的div,但我不知道如何操作。 When i tested, if the link and the div are one after the other, it displays corectly. 当我测试时,如果链接和div是一个接一个的,它会显示出来。 but if i add another link before the first one, it does not work anymore. 但是,如果我在第一个链接之前添加了另一个链接,它将不再起作用。 From my testing using this CSS: 根据我使用此CSS进行的测试:

.expandable{
display: none;
}
.expand:hover+.expandable{
display:inline !important;
}
.expandable:hover{
display:inline !important;
}

And this HTML: 和这个HTML:

<div class="expand">expand</div> <!--this does not do anithing-->
<div class="expand">expand</div> <!--this works-->
<div class="expandable">expandable</div>

Try the below one 试试下面的一个

.expandable{
display: none;
}
.expand:hover ~.expandable{
display:inline !important;
}
.expandable:hover{
display:inline !important;
}

Only the hover on the second div works because of the behaviour of the '+' selector 由于'+'选择器的行为,仅第二个div上的悬停起作用

https://www.w3schools.com/cssref/sel_element_pluss.asp https://www.w3schools.com/cssref/sel_element_pluss.asp

What W3C says : W3C说:

Select and style every p element that are placed immediately after div elements: 选择放置 div元素之后的每个p元素并设置其样式:

div + p { 
    background-color: yellow;
}

you can hide div by id using : jQuery : 您可以使用jQuery通过id隐藏div:

<div id=“div”>

</div>

<script>
$(“#div”).hide("slow"); // you can change "hide" to "show" 
</script>

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

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