CSS transition fade on hover

kwh71787 picture kwh71787 · Oct 20, 2012 · Viewed 116.4k times · Source

I've encountered a problem with CSS transitions. I'm designing a CSS gallery for my portfolio and I need my images to fade in on hover. I've been playing around with this for over an hour and I was hoping someone could point me into the right direction.

Here is a simplified version to it with JSFiddle

Answer

giannis christofakis picture giannis christofakis · May 2, 2013

I recommend you to use an unordered list for your image gallery.

You should use my code unless you want the image to gain instantly 50% opacity after you hover out. You will have a smoother transition.

#photos li {
    opacity: .5;
    transition: opacity .5s ease-out;
    -moz-transition: opacity .5s ease-out;
    -webkit-transition: opacity .5s ease-out;
    -o-transition: opacity .5s ease-out;
}

#photos li:hover {
    opacity: 1;
}