简体   繁体   English

两张照片互相定位。 在悬停时显示一个。 可能与CSS或只有JavaScript?

[英]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.

相关问题 如何验证两个运算符是否没有被放在一起。 计算器Javascript - How to validate that two operators arn't being put after each other. Calculator Javascript CSS:位于绝对位置的div硬币容器中的两个上方的容器 - Css: Two containers above each other in an absolute positioned div cointainer CSS Hover 和 Javascript 在一页上工作而不在另一页上工作? - CSS Hover and Javascript works on one page and not the other? D3将两个圆环图添加到彼此之上。 - D3 adding two donut charts on top of each other. 如何关闭彼此独立的多个div。 JavaScript的 - How to close multiple divs independed from each other. javascript 标签不切换,但堆叠在彼此之上。 JavaScript的 - Tabs not switching, but stacking on top of each other. JavaScript 数据表排序箭头如何成为永久意味着将始终显示不在 hover 上的排序箭头。 在 vuejs+vuetify 中怎么可能? - How datatable sorting arrow to be permanent means will always show the sorting arrow not on hover. How is it possible in vuejs+vuetify? JavaScript:在悬停之前和之后均显示的文本。 - JavaScript: text to appear both before hover and after hover. 没有Javascript(只有CSS)可以做同样的(悬停效果)吗? - Is that possible to do the same (hover effect) without Javascript (only CSS)? 如何仅在悬停幻灯片 html css javascript 时显示箭头 - how to show arrow only when hover slideshow html css javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM