Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color transparency overlay on hover

Working on my personal site and I have images that upon hover I would like to have a dark red overlay that is somewhat transparent. So far all I can find with webkit is changing the brightness, saturation or hue of the photo.

I might add that these features only work when I designate them to tags such as "img" and they don't work with "class" or "id."

Any help would be great.

Here is my code:

html

<div>
<img src="images/amadea/book.jpg" alt="Amadea Bailey- Abstract Expressionist">
</div>

css

img{
    display: block;
}

img:hover{
    -webkit-filter:  grayscale(100%) brightness(51%);
}
like image 888
ncuda Avatar asked Feb 14 '23 23:02

ncuda


1 Answers

You could use an :after pseudo element that is absolutely positioned relative to the parent div elements. The pseudo element would be the same size as the parent, therefore it works for all img dimensions. It basically just adds a transparent overlay on :hover, achieving the 'filter' you're looking for. You can use any background color, customize the transparency and even add content..

EXAMPLE HERE

div {
    position:relative;
    display:inline-block;
}
div:hover:after {
    content:"\A";
    width:100%;
    height:100%;
    background:rgba(255, 0, 0, 0.5);
    position:absolute;
    top:0;
    left:0;
} 
like image 89
Josh Crozier Avatar answered Feb 27 '23 05:02

Josh Crozier