Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3: Use On-hover Event to Set Semi-transparent Overlay on an Image

Tags:

html

css

events

I need an on hover semi-transparent div which causes some text to appear over the top of a thumbnail image? Is it possible to do this without using JavaScript and using just Cascading Style Sheet?

like image 411
Rob Such Avatar asked Mar 01 '10 14:03

Rob Such


People also ask

How do I make a semi transparent background in CSS?

To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

How do you hover an image in CSS?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.

How do you add opacity to an overlay?

To adjust the opacity of an overlay, simply put the mouse cursor (arrow) on the overlay in the Ecamm Live main window, and do a scroll gesture up or down while holding down the shift key on the keyboard.


2 Answers

You can try something like this:

<style type="text/css">
.thumb {position:relative;width:200px;height:20px;}
.thumb:hover .overlay {opacity:0.5;}
.overlay {position:absolute;top:0;left:0;width:200px;height:20px;background:#fff;opacity:0;}
</style>
<div class="thumb">
    <div class="overlay"></div>
    <img src="image.gif" />
</div>
like image 183
easwee Avatar answered Sep 28 '22 04:09

easwee


Ok ok I know this is old but i ran into and have something to add about opacity settings

http://deepubalan.com/blog/2010/03/29/rgba-vs-opacity-the-difference-explained/

give that a look over, I find using rgba when ever possible over opacity procuces a much better result, opacity can work funny in different browsers and cause all manner of asthetic problems... just my 2 cents

like image 25
Taylor Suchan Avatar answered Sep 28 '22 04:09

Taylor Suchan