简体   繁体   English

在图像上用颜色覆盖文本

[英]Overlay text with color over an image

Right now I am overlaying color over an image inside a div. 现在,我将颜色叠​​加在div内的图像上。

CSS: CSS:

.thumb {width:300px;margin:auto;background:rgba(231, 207, 0, 0.5);}
.thumb img { display: block; }
.thumb:hover img { opacity: 0.5; }

HTML: HTML:

<div class="thumb">
<a href="url">
<img src="source"/>
</a>
</div>

How could I also overlay text on hover? 如何在悬停时叠加文字?

I found quite a few tutorials on this but am completely lost how to modify the current code to have text overlay as well. 我找到了很多有关此的教程,但是完全不知道如何修改当前代码以覆盖文本。

You have to position text div abosolute and display it on hover. 您必须将div文本abosolute定位并在悬停时显示它。

 .thumb { width: 300px; margin: auto; background: rgba(231, 207, 0, 0.5); position: relative; } .thumb img { display: block; width: 300px; } .thumb:hover img { opacity: 0.5; } .overlay_text { display: none; position: absolute; bottom: 0; text-align: center; width: 100%; } .thumb:hover .overlay_text { display: block; } 
 <div class="thumb"> <a href="url"> <img src="https://www.gravatar.com/avatar/4ee102e4ae1b9ab69077f7c471365f69?s=128&d=identicon&r=PG&f=1" /> </a> <div class="overlay_text">test</div> </div> 

Go-through the CSS and HTML i did. 通过我做过的CSS和HTML Its working. 它的工作。

Here is Demo: 这是演示:

 .thumb { background: rgba(231, 207, 0, 0.5); display: table; margin: auto; width: 300px; } .thumb img { display: block; margin: 0; position: absolute; top: 7px; } .thumb:hover img { opacity: 0.5; } .caption { display: table-cell; height: 300px; margin: 0; opacity: 0; text-align: center; vertical-align: middle; width: 300px; } .thumb:hover .caption{ opacity:1;} 
 <div class="thumb"> <a href="url"> <p class="caption"> CAPTION</p> <img src="http://placehold.it/300"/> </a> </div> 

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

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