CKTIS / CSS
CSS-Eigenschaft `position`
`position` wählt das Positionierungsschema eines Kastens: `static` lässt ihn unpositioniert, `relative` versetzt ihn nach dem normalen Layout, `absolute` nimmt ihn aus dem Fluss, `sticky` begrenzt seinen Versatz beim Scrollen und `fixed` bindet ihn meist an den Viewport.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
static | relative | absolute | sticky | fixedposition wählt das Positionierungsschema eines Kastens: static lässt ihn unpositioniert, relative versetzt ihn nach dem normalen Layout, absolute nimmt ihn aus dem Fluss, sticky begrenzt seinen Versatz beim Scrollen und fixed bindet ihn meist an den Viewport.
Das Beispiel misst, dass static einen Inset ignoriert, relative die Darstellung verschiebt, ohne das folgende Geschwister zu bewegen, absolute im umschließenden Block keinen Flussraum belegt und fixed nach dem Scrollen seine Viewport-Koordinaten behält.
Grammatik: static | relative | absolute | sticky | fixed.
Jeder Wert außer static erzeugt einen positionierten Kasten und einen absoluten Positionierungsblock für Nachkommen. absolute und fixed blockifizieren den Kasten und können Inhalt überlagern; sticky benötigt einen Inset und einen geeigneten Scrollbereich für sichtbares Anheften.
Beispiele
<!doctype html><meta charset="utf-8"><style>html,body{margin:0}body{height:1000px}.flow{width:40px;height:20px}.cb{position:absolute;left:300px;top:0;width:200px;height:60px}.cb>*{width:20px;height:20px}.fixed{position:fixed;left:8px;top:6px;width:10px;height:10px}</style><div id="staticBox" class="flow" style="position:static;top:25px"></div><div id="relativeBox" class="flow" style="position:relative;top:15px"></div><div id="afterBox" class="flow"></div><div id="cb" class="cb"><i id="absoluteBox" style="position:absolute;left:70px;top:10px"></i><i id="flowBox"></i></div><i id="fixedBox" class="fixed"></i><pre id="result"></pre><script>const point=e=>{const r=e.getBoundingClientRect();return[Math.round(r.left),Math.round(r.top)]},s=point(staticBox),r=point(relativeBox),after=point(afterBox),abs=point(absoluteBox),flow=point(flowBox),before=point(fixedBox),values=[staticBox,relativeBox,absoluteBox,fixedBox].map(e=>getComputedStyle(e).position);scrollTo(0,200);requestAnimationFrame(()=>{const fixedAfter=point(fixedBox);if(s.join(',')!=='0,0'||r.join(',')!=='0,35'||after.join(',')!=='0,40'||abs.join(',')!=='370,10'||flow.join(',')!=='300,0'||before.join(',')!=='8,6'||fixedAfter.join(',')!=='8,6'||values.join('/')!=='static/relative/absolute/fixed')throw new Error('position geometry mismatch '+[s,r,after,abs,flow,before,fixedAfter,values]);result.textContent='flow='+s.join(',')+'/'+r.join(',')+'/'+after.join(',')+'; abs='+abs.join(',')+' flow-sibling='+flow.join(',')+'; fixed='+before.join(',')+'->'+fixedAfter.join(',')+'; computed='+values.join('/')});</script>Ergebnis
flow=0,0/0,35/0,40; abs=370,10 flow-sibling=300,0; fixed=8,6->8,6; computed=static/relative/absolute/fixed
Das Beispiel misst, dass `static` einen Inset ignoriert, `relative` die Darstellung verschiebt, ohne das folgende Geschwister zu bewegen, `absolute` im umschließenden Block keinen Flussraum belegt und `fixed` nach dem Scrollen seine Viewport-Koordinaten behält.