Transitioning to display: none in CSS
The trick that used to need a timeout: two extra lines and the element can animate out.
.popover {
opacity: 0;
display: none;
transition: opacity 200ms ease, display 200ms allow-discrete;
}
.popover.is-open {
opacity: 1;
display: block;
}
@starting-style {
.popover.is-open { opacity: 0; }
}
dialog::backdrop {
background: rgb(15 23 42 / 0.4);
transition: opacity 200ms ease, overlay 200ms allow-discrete;
}
How it works
transition-behavior: allow-discreteletsdisplaytake part.@starting-stylegives the browser a value to animate from on first paint.overlaykeeps a top-layer element visible while it animates away.
Keywords and builtins used here
backgrounddisplaymsopacitypopoverrgbtransition
The run, in numbers
- Lines
- 19
- Characters to type
- 322
- Tokens
- 80
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 53 seconds.
Step 2 of 8 in Motion & effects, step 12 of 21 in Responsive & modern CSS.