WissensdatenbankPrüfungszentrum
DEDeutsch
Sprache wählen13

CKTIS / CSS

CSS-Eigenschaft `justify-self`

`justify-self` richtet ein einzelnes Grid- oder positioniertes Element auf der Inlineachse seines Bereichs aus.

Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Syntax

auto | normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | anchor-center

justify-self richtet ein einzelnes Grid- oder positioniertes Element auf der Inlineachse seines Bereichs aus.

Das Beispiel lässt justify-items:start am Container und verschiebt nur das geprüfte Kind nach center.

Grammatik: auto | normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | anchor-center.

Die Hauptachse eines Flex-Elements wird nicht beeinflusst; auto folgt meist dem Container und stretch braucht eine automatische Größe.

Beispiele

<!doctype html><html lang="en"><meta charset="utf-8"><title>CKTIS CSS example</title><body><pre id="result"></pre><script>const g=document.createElement("div"),x=document.createElement("i");document.body.prepend(g);g.append(x);g.style.cssText="display:grid;width:100px;height:40px;grid-template-columns:100px;justify-items:start";x.style.cssText="width:20px;height:10px";const a=g.getBoundingClientRect(),x0=Math.round(x.getBoundingClientRect().left-a.left);x.style.justifySelf="center";const x1=Math.round(x.getBoundingClientRect().left-a.left);document.querySelector("#result").textContent="child-x="+x0+"->"+x1+"; container="+getComputedStyle(g).justifyItems+"; computed="+getComputedStyle(x).justifySelf;</script></body></html>

Ergebnis

child-x=0->40; container=start; computed=center

Das Beispiel lief lokal in einer isolierten Chrome-Sitzung ohne Netzwerk; das Ergebnis stammt aus der CSS-API des Browsers.

Quellen