I want to change z-index
of a div when the opacity translations
has finished, only with CSS3 properties.
There is any way that I can do that?
Follows the CSS3 code:
.high-light{
position: fixed;
width: 100%;
height: 100%;
top: 0;
background-color: black;
background-color: rgba(0, 0, 0, 0.61);
opacity:0;
left: 0;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 0.3s linear;
z-index: 1;
}
.high-light.high-light-active {
opacity:1;
z-index: 1;
}
Note: When the div has the class high-light-active
, I want first, the transition happens and after the change of z-index value
.
So remember: z-index is indeed one of the properties you can apply a transition to, but the transition has to happen in full steps, not necessarily as gradually as you might imagine it in your head.
Yes, you can animate z-index ! It's not visually apparent in this demo, but seeing the interpolated values go from 1 to 5 confirms it.
You set z-index on a static element By default, every element has a position of static. z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.
Note: Z index only works on positioned elements ( position:absolute , position:relative , or position:fixed ).
It's also possible with the 3rd parameter of transition
(the delay value):
h2 {
background: rgba(255,192,192,.7);
padding: 1em;
margin: 0;
}
div {
position: fixed;
padding: 20px;
background: #888;
color: #fff;
z-index: -1;
opacity: 0;
transition: opacity 1s, z-index .2s 1s;
margin-top: -10px;
}
h2:hover + div {
z-index: 1;
opacity: 1;
}
<h2>Hover to see the transition</h2>
<div>Changing</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With