3.5 · Popovers & positioning
Your own fallbacks: @position-try
Define your own fallback positions for anchored elements.
flip-block and flip-inline cover the common
cases. When you need more,
@position-try --name { … } defines a named fallback with
its own position-area, margins and size.
List them in position-try-fallbacks and the browser tries
each in order until one fits.
position-try-order: most-height or
most-width picks whichever option leaves the most room
instead.
// Floating UI
computePosition(anchor, tooltip, {
placement: 'top',
middleware: [flip({
fallbackPlacements: ['right', 'bottom'],
})],
})
@position-try --beside {
position-area: inline-end;
margin-inline-start: 0.75rem;
}
.tooltip {
position-area: block-start;
position-try-fallbacks: --beside, --below;
}