Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a CSS gradient to an image--NOT a background image

Tags:

css

gradient

This is a page that uses a carousel (I believe flexslider). The images in this carrousel are NOT background images. I need to add a gradient to the image, going from the bottom up, and from dark to zero opacity, so that I can make the text more legible. Is this possible?

http://hungersolutionsny.magadev.net

like image 299
MDLG Avatar asked Dec 25 '22 23:12

MDLG


1 Answers

Personally I am not a big fan of adding markup just for styling. I would go for a pseudo element :before or :after

The code would look something like this:

HTML

<div class='slideshow-wrapper'>
    <img src='http://www.placekitten.com/800/300'/>
    <h2 class='title'>Some title</h2>
</div>

CSS

.slideshow-wrapper {
    position:relative;
    float: left;
}
.title {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 2;
}
.slideshow-wrapper:before {
    content: '';
    position:absolute;
    top:0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%);
    z-index: 1;
}

And an example: http://jsfiddle.net/VrGeM/

like image 101
Pevara Avatar answered Jan 13 '23 00:01

Pevara