I have got a problem with a CSS3 animation.
.child {
opacity: 0;
display: none;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
.parent:hover .child {
opacity: 0.9;
display: block;
}
This code only works if I remove the change of display
.
I want to change the display just after the hover but the opacity should be changed using the transition.
This workaround works:
define a “keyframe”:
Use this “keyframe” on “hover”:
There is another good method to get this done by using pointer-events:
Unfortunately, this is not supported in IE10 and below.
I know, this is not really a solution for your question, because you ask for
My approach solves a more general question, but maybe this was the background problem that should be solved by using
display
in combination withopacity
.My desire was to get the Element out of the way when it is not visible. This solution does exactly that: It moves the element out of the away, and this can be used for transition:
This code does not contain any browser prefixes or backward compatibility hacks. It just illustrates the concept how the element is moved away as it is not needed any more.
The interesting part are the two different transition definitions. When the mouse-pointer is hovering the
.parent
element the.child
element needs to be put in place immediately and then the opacity will be changed:When there is no hover, or the mouse-pointer was moved off the element, one has to wait until the opacity change has finished before the element can be moved off screen:
Moving the object away will be a viable alternative in a case where setting
display:none
would not break the layout.I hope I hit the nail on the head for this question although I did not answer it.
display:
is not transitionable. You'll probably need to use jQuery to do what you want to do.I used this to achieve it. They fade on hover but take no space when hidden, perfect!
On absolute or fixed elements you could also use z-index:
Other elements should have a z-index between -100 and 100 now.