Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS transition fade on hover

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

like image 773
kwh71787 Avatar asked Oct 20 '12 20:10

kwh71787


People also ask

How do you slow down a hover?

To set the speed of the hover, use the transition-duration property. To set the hover, use the :hover selector.

What is hover transition?

CSS transitions allows you to change property values smoothly (from one value to another), over a given duration.

How do you make a fade effect in CSS?

Method 1: Using CSS animation property: A CSS animation is defined with 2 keyframes. One with the opacity set to 0, the other with the opacity set to 1. When the animation type is set to ease, the animation smoothly fades in the page. This property is applied to the body tag.


2 Answers

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;
}
like image 154
giannis christofakis Avatar answered Oct 26 '22 00:10

giannis christofakis


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;
}
like image 15
Darwayne Avatar answered Oct 26 '22 00:10

Darwayne