Saltar al contenido

Propiedad CSS align-content

La propiedad CSS align-content alinea las líneas de un contenedor flex cuando hay espacio disponible en el eje transversal.

La propiedad align-content es una de las propiedades CSS3.

Cuando solo hay una línea en el flexbox, esta propiedad no tiene efecto. Necesita múltiples líneas dentro de un contenedor flexible.

El valor stretch es el valor predeterminado de esta propiedad.

La propiedad align-content acepta los siguientes valores:

  • flex-start
  • flex-end
  • center
  • space-between
  • space-around
  • space-evenly
  • stretch
Valor inicialstretch
Se aplica aContenedores flex de varias líneas.
HeredableNo.
AnimableNo.
VersiónCSS3
Sintaxis DOMobject.style.alignContent = "flex-end";

Sintaxis

Sintaxis de la propiedad CSS align-content

css
align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | initial | inherit;

Ejemplo de la propiedad align-content con el valor stretch:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      #example {
        width: 70px;
        height: 300px;
        padding: 0;
        border: 1px solid #c3c3c3;
        display: flex;
        flex-flow: row wrap;
        align-content: stretch;
      }
      #example li {
        width: 70px;
        height: 70px;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-content: stretch; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;"></li>
      <li style="background-color:#1c87c9;"></li>
      <li style="background-color:#666;"></li>
    </ul>
  </body>
</html>

Resultado

Propiedad CSS align-content con el valor stretch

Ejemplo de la propiedad align-content con el valor "center":

html
<!DOCTYPE html>
<html>
  <head>
    <style>
      #example {
        width: 70px;
        height: 300px;
        padding: 0;
        border: 1px solid #c3c3c3;
        display: flex;
        flex-flow: row wrap;
        align-content: center;
      }
      #example li {
        width: 70px;
        height: 70px;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-content: center; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;"></li>
      <li style="background-color:#1c87c9;"></li>
      <li style="background-color:#666;"></li>
    </ul>
  </body>
</html>

Ejemplo de la propiedad align-content con el valor "flex-start":

html
<!DOCTYPE html>
<html>
  <head>
    <style>
      #example {
        width: 70px;
        height: 300px;
        padding: 0;
        border: 1px solid #c3c3c3;
        display: flex;
        flex-flow: row wrap;
        align-content: flex-start;
      }
      #example li {
        width: 70px;
        height: 70px;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-content: flex-start; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;"></li>
      <li style="background-color:#1c87c9;"></li>
      <li style="background-color:#666;"></li>
    </ul>
  </body>
</html>

Ejemplo de la propiedad align-content con el valor "flex-end":

html
<!DOCTYPE html>
<html>
  <head>
    <style>
      #example {
        width: 70px;
        height: 300px;
        padding: 0;
        border: 1px solid #c3c3c3;
        display: flex;
        flex-flow: row wrap;
        align-content: flex-end;
      }
      #example li {
        width: 70px;
        height: 70px;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-content: flex-end; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;"></li>
      <li style="background-color:#1c87c9;"></li>
      <li style="background-color:#666;"></li>
    </ul>
  </body>
</html>

En el siguiente ejemplo, el espacio se distribuye uniformemente entre las líneas flex.

Ejemplo de la propiedad align-content con el valor "space-between":

html
<!DOCTYPE html>
<html>
  <head>
    <style>
      #example {
        width: 70px;
        height: 300px;
        padding: 0;
        border: 1px solid #c3c3c3;
        display: flex;
        flex-flow: row wrap;
        align-content: space-between;
      }
      #example li {
        width: 70px;
        height: 70px;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-content: space-between; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;"></li>
      <li style="background-color:#1c87c9;"></li>
      <li style="background-color:#666;"></li>
    </ul>
  </body>
</html>

Resultado

Propiedad CSS align-content con el valor space-between

Otro ejemplo con el valor "space-around". Hay un espacio igual entre las líneas flex.

Ejemplo de la propiedad align-content con el valor “space-around”:

html
<!DOCTYPE html>
<html>
  <head>
    <style>
      #example {
        width: 70px;
        height: 300px;
        padding: 0;
        border: 1px solid #c3c3c3;
        display: flex;
        flex-flow: row wrap;
        align-content: space-around;
      }
      #example li {
        width: 70px;
        height: 70px;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-content: space-around; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;"></li>
      <li style="background-color:#1c87c9;"></li>
      <li style="background-color:#666;"></li>
    </ul>
  </body>
</html>

Valores

ValorDescripciónProbarlo
stretchEstira los elementos para que se ajusten al contenedor. Este es el valor predeterminado de esta propiedad.Probarlo »
centerLos elementos se colocan en el centro del contenedor.Probarlo »
flex-startLos elementos se colocan al principio del contenedor.Probarlo »
flex-endLos elementos se colocan al final del contenedor.Probarlo »
space-betweenDistribuye el espacio uniformemente entre las líneas flex.Probarlo »
space-aroundLos elementos se distribuyen con un espacio igual entre ellos.Probarlo »
space-evenlyDistribuye los elementos con un espacio igual entre ellos, así como antes del primero y después del último elemento.Probarlo »
initialHace que la propiedad use su valor predeterminado.Probarlo »
inheritHereda la propiedad de su elemento padre.

Práctica

¿Cuáles son los valores posibles para la propiedad CSS align-content?

¿Te resulta útil?

Vista previa dual-run — compárala con las rutas Symfony en producción.