[英]Two photos positioned on each other. Show one on hover. Possible with css or only javascript?
What I want to do is to show the top photo (which is set to visibility: hidden) on hover. 我想要做的是在悬停时显示顶部照片(设置为可见性:隐藏)。 I have two photos positioned on each other like this:
我有两张照片彼此相邻:
<div class="frame">
<img src="./img/portfolio/default1.jpg" width="300" height="178" alt="Title Here"></a>
<a href="http://www.mylink.com"><div class="boxwrapper" style="visibility: hidden;"></div></a>
</div>
Added the second photo through css: 通过css添加了第二张照片:
.boxwrapper {
background: url("../img/boxPlus.gif");
position: relative;
width: 300px;
height: 178px;
left: -6px;
top: -184px;
z-index: 1000;
}
Is it possible to do with css? 可以用css吗? Tried (and several more options):
尝试过(以及其他几个选项):
#frame img:hover .boxwrapper {
visibility: visible;
}
But it is not working. 但它没有用。 Or this is only possible with javascript?
或者这只能用javascript实现? If yes, please give some tips as I am not too much of javascript guy.
如果是的话,请提供一些提示,因为我不是太多的javascript家伙。 Thanks!
谢谢!
You'd have to put the :hover class on a parent container. 您必须将:hover类放在父容器上。 CSS does not allow such things to trickle "up" the tree, only down.
CSS不允许这样的东西涓涓细流“向上”树,只有向下。
.boxwrapper {
display: none;
}
.frame:hover .boxwrapper {
display: block;
}
You could set the photo as background of the boxwrapper
您可以将照片设置为
boxwrapper
背景
.boxwrapper{
background: url("../img/boxPlus.gif");
}
.boxwrapper:hover{
background: url("../img/portfolio/default1.jpg");
}
if this is not possible you could add it as background trough a style attribute inside your html 如果这不可能,您可以通过html中的样式属性将其添加为背景
<div class="boxwrapper" style="background: url('../img/boxPlus.gif');" ></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.