How to give hover opacity effect in img's?

0

I would like to know how to put a hover effect on the img's site link .

    
asked by anonymous 09.12.2015 / 23:18

1 answer

1

You can simply place a dark background and give opacity in the image when passing the mouse that will give that effect. An example would look like this:

.darken {
    display: inline-block;
    background: black;
    padding: 0;
}


.darken:hover img {
    opacity: 0.7;      
}
.darken img {
    display: block;
    
    -webkit-transition: all 0.5s linear;
       -moz-transition: all 0.5s linear;
        -ms-transition: all 0.5s linear;
         -o-transition: all 0.5s linear;
            transition: all 0.5s linear;
}
<a href="http://google.com" class="darken">
    <img src="http://www.prelovac.com/vladimir/wp-content/uploads/2008/03/example.jpg"width="200">
</a>

Where am I putting the dark background with this code:

.darken {
        display: inline-block;
        background: black;
        padding: 0;
    }

If you want to better understand the operation, change this line background: black; to another color, for example: background: blue; that will turn blue instead of black.

And when you move the mouse, setting the opacity of it, in this part:

.darken:hover img {
        opacity: 0.7;      
    }

The last part is for transition only.

Source: SO

    
09.12.2015 / 23:27