CSS transition fade on hover

123,831

Solution 1

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;
}

Solution 2

This will do the trick

.gallery-item
{
  opacity:1;
}

.gallery-item:hover
{
  opacity:0;
  transition: opacity .2s ease-out;
  -moz-transition: opacity .2s ease-out;
  -webkit-transition: opacity .2s ease-out;
  -o-transition: opacity .2s ease-out;
}
Share:
123,831

Related videos on Youtube

kwh71787
Author by

kwh71787

BY DAY: Senior WordPress Theme Developer at LinkNow Media BY NIGHT: PSD to WordPress Theme Developer at Element Web Designs. FOR FUN: Killing the biggest dragons I can find in either Final Fantasy XIV or World of Warcraft. Also, pwning noobs on Dota2 INSPIRATION: Give me six hours to chop down a tree and I will spend the first four sharpening the axe. -Abraham Lincoln

Updated on August 20, 2020

Comments

  • kwh71787
    kwh71787 over 3 years

    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

  • giannis christofakis
    giannis christofakis about 11 years
    You forgot to place the seconds unit measurement on the -moz-transition
  • Matt
    Matt almost 10 years
    It was having opacity set on the non-:hover element that caused my problem.
  • SerKnight
    SerKnight about 8 years
    Also this will snap back at 0.0 speed when you release the hover