Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / CSS

Vlastnosť CSS `justify-content`

`justify-content` rozdeľuje voľné miesto medzi položky flex či stopy grid a okolo nich na hlavnej alebo riadkovej osi.

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

Syntax

normal | <content-distribution> | <overflow-position>? [ <content-position> | left | right ]

justify-content rozdeľuje voľné miesto medzi položky flex či stopy grid a okolo nich na hlavnej alebo riadkovej osi.

Príklad porovná polohu prvej položky pri start a center vo flex kontajneri pevnej šírky.

Gramatika: normal | <content-distribution> | <overflow-position>? [ <content-position> | left | right ].

Bez voľného miesta nenastane posun; vlastnosť nenahrádza justify-self a bezpečné zarovnanie môže ustúpiť ku start.

Príklady

<!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");g.innerHTML="<i></i><i></i>";document.body.prepend(g);g.style.cssText="display:flex;width:120px;height:40px";for(const x of g.children)x.style.cssText="width:20px;height:10px";const a=g.getBoundingClientRect();g.style.justifyContent="start";const x0=Math.round(g.firstElementChild.getBoundingClientRect().left-a.left);g.style.justifyContent="center";const x1=Math.round(g.firstElementChild.getBoundingClientRect().left-a.left);document.querySelector("#result").textContent="first-x="+x0+"->"+x1+"; computed="+getComputedStyle(g).justifyContent;</script></body></html>

Výsledok

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

Príklad bol spustený lokálne v izolovanej relácii Chrome bez siete; výsledok pochádza z CSS API prehliadača.

Zdroje