Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / CSS

Propiedad CSS `justify-content`

`justify-content` distribuye espacio libre entre y alrededor de elementos flex o pistas grid en el eje principal o en línea.

Versión: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Sintaxis

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

justify-content distribuye espacio libre entre y alrededor de elementos flex o pistas grid en el eje principal o en línea.

El ejemplo compara la posición del primer elemento con start y center en un contenedor flex de anchura fija.

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

Sin espacio libre no hay desplazamiento; no sustituye justify-self y una alineación segura puede volver hacia start.

Ejemplos

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

Resultado

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

El ejemplo se ejecutó localmente en una sesión aislada de Chrome sin red; el resultado procede de la API CSS del navegador.

Fuentes