База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / CSS

CSS свойство `justify-content`

`justify-content` разпределя свободното място между и около flex елементи или grid писти по главната или inline оста.

Версия: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Синтаксис

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

justify-content разпределя свободното място между и около flex елементи или grid писти по главната или inline оста.

Примерът сравнява позицията на първия елемент при start и center във flex контейнер с фиксирана ширина.

Граматика: normal | <content-distribution> | <overflow-position>? [ <content-position> | left | right ].

Без свободно място няма преместване; не заменя justify-self, а безопасното подравняване може да се върне към start.

Примери

<!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>

Резултат

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

Примерът е изпълнен локално в изолирана Chrome сесия без мрежа; резултатът идва от CSS API на браузъра.

Източници