Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 - Change z-index after css3 transition ends

Tags:

css

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.

like image 889
Ricardo Rocha Avatar asked Sep 12 '16 13:09

Ricardo Rocha


People also ask

Can Z index be transitioned?

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.

Can you animate Z Index CSS?

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.

Why is Z Index not working CSS?

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.

Does Z Index work with position relative?

Note: Z index only works on positioned elements ( position:absolute , position:relative , or position:fixed ).


1 Answers

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>
like image 183
Ilya Streltsyn Avatar answered Oct 09 '22 19:10

Ilya Streltsyn