Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / CSS

Właściwość CSS `justify-items`

`justify-items` ustala domyślną wartość justify-self elementów grid w osi inline ich obszarów.

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

Składnia

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

justify-items ustala domyślną wartość justify-self elementów grid w osi inline ich obszarów.

Przykład przesuwa rzeczywiste dziecko grid ze start do center i mierzy jego współrzędną x.

Gramatyka: normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | legacy | legacy && [ left | right | center ] | anchor-center.

justify-self dziecka nadpisuje tę wartość; w flexbox część justify-items nie pozycjonuje elementów flex.

Przykłady

<!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";x.style.cssText="width:20px;height:10px";const a=g.getBoundingClientRect();g.style.justifyItems="start";const x0=Math.round(x.getBoundingClientRect().left-a.left);g.style.justifyItems="center";const x1=Math.round(x.getBoundingClientRect().left-a.left);document.querySelector("#result").textContent="child-x="+x0+"->"+x1+"; computed="+getComputedStyle(g).justifyItems;</script></body></html>

Wynik

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

Przykład uruchomiono lokalnie w izolowanej, bezsieciowej sesji Chrome; wynik pochodzi z API CSS przeglądarki.

Źródła