[英]How to display a div when hovering over another div
Here my first div shows an image. 在这里,我的第一个div显示了一张图片。 If you mouse hover on the image then it should show another div named
hdiv
. 如果将鼠标悬停在图像上,则它应显示另一个名为
hdiv
div。
Here $pitem[6] return data from database with php for loop. 这里$ pitem [6]用php for loop从数据库返回数据。
CODE 码
<div class="pcimga">
<div class="pcimg"><img src="Portfolio_Image/'.$pitem[6].'" class="pcimg" /></div>
<div class="hdiv" style="display:none;">
<span class=" butnn"><a data-toggle="modal" href="#myModal'.$pitem[0].'">View</a>
</div>
</div>
try this... 尝试这个...
.pgimga:hover~.hdiv
{
display:block;
}
let me know if you want any further guidance.. 让我知道您是否需要任何进一步的指导。
You can do it with pure CSS: 您可以使用纯CSS来做到这一点:
1. When .hdiv is next to .pcimg 1.当 .hdiv 毗邻 .pcimg
.pcimg:hover+.hdiv{
display:block !important;
}
2. When there is gap between .hdiv and .pcimg 2. .hdiv 和 .pcimg 之间存在间隙时
.pcimg:hover~.hdiv{
display:block !important;
}
Note : Internal styles have higher priority than External styles.So for giving External styles more priority !important
is needed 注意:内部样式的优先级高于外部样式,因此要为外部样式赋予更高的优先级
!important
Try this in CSS. 在CSS中尝试一下。 You need to use !important to override the inline style "display:none"
您需要使用!important覆盖内联样式“ display:none”
.pcimg:hover+.hdiv
{
display:inherit !important;
}
You can do it like this with onmouseover and onmouseout events using jquery: 您可以使用jquery使用onmouseover和onmouseout事件来做到这一点:
<div class="pcimga">
<div class="pcimg"><img onmouseover='$(".hdiv").show();' onmouseout='$(".hdiv").hide();' src="Portfolio_Image/'.$pitem[6].'" class="pcimg" /></div>
<div class="hdiv" style="display:none;">
<span class=" butnn"><a data-toggle="modal" href="#myModal'.$pitem[0].'">View</a>
</div>
</div>
if you have multiple instances of this block, all of the images will be visible though. 如果您有该块的多个实例,则所有图像都将可见。 to distinguish which one is hovered you can send hideDiv(this) and get which image hovered to show appropriate image.
要区分悬停的图像,可以发送hideDiv(this)并获得悬停的图像以显示适当的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.