如何将文字悬停在图像上?我希望文本框能够完全覆盖图像所在的位置,从而使图像完整消失,并在鼠标移出时重新渲染图像。我搜索everywere,但我只发现悬停效果与图像所在的hoverbox的不同positionig ...将文字悬停在图像上
0
A
回答
1
CSS:
.textHover {
display:none;
width:100%;
height:100%;
position:absolute;
top:0; left:0;
text-align:center;
color:white;
}
.imgContain {
position:relative;
display:table;
}
.imgContain:hover .textHover {
display:block;
}
标记:
<div class="imgContain">
<img src="http://placehold.it/300x200"/>
<div class="textHover">My text here</div>
</div>
+0
这样做的工作......非常感谢 – 2013-03-08 16:59:34
1
不需要JavaScript,除非你需要一些平滑过渡而不依赖于CSS3。假设图像具有固定的尺寸,你可以这样做:
<div>
<p>Text</p>
<img src="" alt="" width="100px" height="100px" />
</div>
div { position:relative; z-index:1; height:100px; width:100px; }
img { position:absolute; top:0; left:0; z-index:2; }
div:hover img { display:none; }
+0
感谢詹姆斯......但它并没有随着我的意愿而变得模糊,无论如何,非常感谢您花费的时间。 – 2013-03-08 17:02:54
0
你不需要JavaScript代码来做到这一点。在纯HTMLcss中,它将运行良好。下面是带有不透明度变化的css动画的例子。
HTML
<div class="hvrbox"> <img src="https://upload.wikimedia.org/wikipedia/commons/2/22/Bochnia_poland_saltmine.jpg" alt="Salt mine" class="hvrbox-layer_bottom"> <div class="hvrbox-layer_top"> <div class="hvrbox-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce porttitor ligula porttitor, lacinia sapien non.</div> </div> </div>
CSS
.hvrbox, .hvrbox * { box-sizing: border-box; } .hvrbox { position: relative; display: inline-block; overflow: hidden; max-width: 100%; height: auto; } .hvrbox img { max-width: 100%; } .hvrbox .hvrbox-layer_bottom { display: block; } .hvrbox .hvrbox-layer_top { opacity: 0; position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); color: #fff; padding: 15px; -moz-transition: all 0.4s ease-in-out 0s; -webkit-transition: all 0.4s ease-in-out 0s; -ms-transition: all 0.4s ease-in-out 0s; transition: all 0.4s ease-in-out 0s; } .hvrbox:hover .hvrbox-layer_top, .hvrbox.active .hvrbox-layer_top { opacity: 1; } .hvrbox .hvrbox-text { text-align: center; font-size: 18px; display: inline-block; position: absolute; top: 50%; left: 50%; -moz-transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } .hvrbox .hvrbox-text_mobile { font-size: 15px; border-top: 1px solid rgb(179, 179, 179); /* for old browsers */ border-top: 1px solid rgba(179, 179, 179, 0.7); margin-top: 5px; padding-top: 2px; display: none; } .hvrbox.active .hvrbox-text_mobile { display: block; }
我有很多类似的例子说明它(更好的动画)这里http://goo.gl/EECjCm
相关问题
- 1. 悬停在图像上的文字
- 2. 在图像悬停上激活文字悬停
- 3. CSS:悬停 - 如何使:悬停在文字上影响图像?
- 4. 将文字悬停在图片上
- 5. 悬停上的文字显示图像
- 6. 将鼠标悬停在图像上时显示文字
- 7. 将鼠标悬停在图像上时出现文字
- 8. 使用HTML/CSS将文字定位在悬停的图像上
- 9. 将鼠标悬停在图像上
- 10. 将光标悬停在图像上?
- 11. 将HTML悬停在图像上
- 12. 图像将留在悬停
- 13. 如何在悬停文字时设置图像的悬停?
- 14. 将图像悬停在图像前
- 15. CSS悬停在图像问题上悬停在链接上?
- 16. 当鼠标悬停在图像上时,在图像上显示文字
- 17. CSS悬停在点上以显示图像 - 不在图像上悬停
- 18. 悬停在文字上打开图片
- 19. 在CSS中,如何将图像悬停在图像上
- 20. 如何在Flash CS3中将文字悬停在文本上时显示图像?
- 21. 将图像悬停在另一个图像上
- 22. 将鼠标悬停在另一图像上时显示图像
- 23. CSS将图像悬停在图像上的链接
- 24. 将鼠标悬停在图像上时删除图像标题
- 25. 将图像悬停在另一张图像上
- 26. 将鼠标悬停在图像上的多个图像更改
- 27. 将图像悬停在图像上时jQuery中的问题?
- 28. 艺术文字悬停下图像
- 29. 将鼠标悬停在文本上,图像淡入
- 30. 将鼠标悬停在文本上时显示图像
欢迎StackOverflow上。人们愿意帮助你,但不会为你做所有的工作。显示你到目前为止所做的。 – 2013-03-08 16:14:29
http://mattgemmell.com/2008/12/08/what-have-you-tried/ – 2013-03-08 16:15:23