Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `position-try`

`position-try` is a shorthand that sets the `position-try-fallbacks` list and its `position-try-order` sorting mode for an absolutely positioned box.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

<'position-try-order'>? <'position-try-fallbacks'>

position-try is a shorthand that sets the position-try-fallbacks list and its position-try-order sorting mode for an absolutely positioned box.

The example declares most-height flip-block; the shorthand sets the order to most-height, the list to flip-block, and chooses space above an anchor near the bottom edge instead of overflowing below it.

Grammar: <'position-try-order'>? <'position-try-fallbacks'>.

The order component is optional and must precede the list; omitting it resets that longhand to normal. The shorthand creates no new option itself. With most-height or another size-based order, the full position-option list—including the base styles—is stably sorted before fit testing, so an alternative may precede a base option that would also fit.

Examples

<!doctype html><meta charset="utf-8"><style>html,body{margin:0}.stage{position:relative;width:200px;height:200px}.anchor{position:absolute;left:80px;top:170px;width:40px;height:20px;anchor-name:--a}.tip{position:absolute;position-anchor:--a;position-area:block-end;width:80px;height:40px;position-try:most-height flip-block}</style><div class="stage"><i class="anchor"></i><b id="tip" class="tip"></b></div><pre id="result"></pre><script>const s=getComputedStyle(tip),r=tip.getBoundingClientRect(),p=[Math.round(r.left),Math.round(r.top)];if(p.join(',')!=='60,130'||s.positionTryOrder!=='most-height'||s.positionTryFallbacks!=='flip-block')throw new Error('position-try mismatch '+[p,s.positionTryOrder,s.positionTryFallbacks]);result.textContent='point='+p.join(',')+'; order='+s.positionTryOrder+'; fallbacks='+s.positionTryFallbacks;</script>

Result

point=60,130; order=most-height; fallbacks=flip-block

The example declares `most-height flip-block`; the shorthand sets the order to `most-height`, the list to `flip-block`, and chooses space above an anchor near the bottom edge instead of overflowing below it.

Sources