brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: transition-behavior: allow-discrete in CSS animates a popover as it closes

Css
~/tips/tip-css-allow-discrete-display-exit

[popover] {

Elements that switch to display: none can fade out instead of vanishing at once.

An element that goes to display: none disappears instantly, so any fade you set never gets the chance to run. allow-discrete lets the browser keep it visible until the transition is done.

[popover] {
  opacity: 0;
  transition:
    opacity 0.2s,
    display 0.2s allow-discrete,
    overlay 0.2s allow-discrete;
}
[popover]:popover-open {
  opacity: 1;
}
@starting-style {
  [popover]:popover-open { opacity: 0; }
}

display is a discrete property: it has no values in between. Normally such properties are not transitioned at all. With allow-discrete (here as a keyword in the shorthand) the browser flips display at the end of the closing transition instead of the start, so the opacity fade is visible. overlay does the same for leaving the top layer. The @starting-style block handles the opening side.

I would call support uneven. Chrome 117 and Safari 17.4 support the property. MDN lists Firefox 129 as partial: it does not transition display this way, so in Firefox the popover still disappears instantly, which is a harmless fallback. The overlay property is Chromium only, and other browsers simply ignore that part of the list.

Further reading: MDN: transition-behavior, MDN: overlay

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link