Propriété CSS grid-auto-columns

La propriété grid-auto-columns spécifie la taille des colonnes sur la grille.

Valeur initiale auto
Appliquée à Conteneurs de grille.
Héritée Non.
Animable Oui. La taille des colonnes est animable.
Version CSS Grid Layout Module Level 1
Syntaxe DOM object.style.gridAutoColumns = "100px";

Syntaxe

grid-auto-columns: auto | max-content | min-content | length | initial | inherit;

Exemple

<!DOCTYPE html>
<html>
  <head>
    <title>Titre du document</title>
    <style>
      .box1 { grid-area: 1 / 1 / 2 / 2; }
      .box2 { grid-area: 1 / 2 / 2 / 3; }
      .box3 { grid-area: 1 / 3 / 2 / 4; }
      .box4 { grid-area: 2 / 1 / 3 / 2; }
      .box5 { grid-area: 2 / 2 / 3 / 3; }
      .box6 { grid-area: 2 / 3 / 3 / 4; }
      .black-box1 { grid-area: 1 / 1 / 2 / 2; }
      .black-box2 { grid-area: 1 / 2 / 2 / 3; }
      .black-box3 { grid-area: 1 / 3 / 2 / 4; }
      .black-box4 { grid-area: 2 / 1 / 3 / 2; }
      .black-box5 { grid-area: 2 / 2 / 3 / 3; }
      .black-box6 { grid-area: 2 / 3 / 3 / 4; }
      .auto-box1 { grid-area: 1 / 1 / 2 / 2; }
      .auto-box2 { grid-area: 1 / 2 / 2 / 3; }
      .auto-box3 { grid-area: 1 / 3 / 2 / 4; }
      .auto-box4 { grid-area: 2 / 1 / 3 / 2; }
      .auto-box5 { grid-area: 2 / 2 / 3 / 3; }
      .auto-box6 { grid-area: 2 / 3 / 3 / 4; }
      .grid-container {
      display: grid;
      grid-auto-columns: 50px;
      grid-gap: 10px;
      background-color: #555;
      padding: 10px;
      }
      .grid-container > div {
      background-color: #ccc;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
      .black-container {
      display: grid;
      grid-auto-columns: 100px;
      grid-gap: 10px;
      background-color: #000;
      padding: 10px;
      }
      .black-container > div {
      background-color: #ccc;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
      .auto-container {
      display: grid;
      grid-auto-columns: auto;
      grid-gap: 10px;
      background-color: #ccc;
      padding: 10px;
      }
      .auto-container > div {
      background-color: #999;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Exemple de la propriété grid-auto-columns</h2>
    <h3>50 pixels</h3>
    <div class="grid-container">
      <div class="box1">1</div>
      <div class="box2">2</div>
      <div class="box3">3</div>
      <div class="box4">4</div>
      <div class="box5">5</div>
      <div class="box6">6</div>
    </div>
    <h3>100 pixels</h3>
    <div class="black-container">
      <div class="black-box1">1</div>
      <div class="black-box2">2</div>
      <div class="black-box3">3</div>
      <div class="black-box4">4</div>
      <div class="black-box5">5</div>
      <div class="black-box6">6</div>
    </div>
    <h3>auto</h3>
    <div class="auto-container">
      <div class="auto-box1">1</div>
      <div class="auto-box2">2</div>
      <div class="auto-box3">3</div>
      <div class="auto-box4">4</div>
      <div class="auto-box5">5</div>
      <div class="auto-box6">6</div>
    </div>
  </body>
</html><!DOCTYPE html>
<html>
  <head>

Voici un exemple qui contient tous les valeurs:

Exemple

<!DOCTYPE html>
<html>
  <head>
    <title>Titre du document</title>
    <style>
      .box1 { grid-area: 1 / 1 / 2 / 2; }
      .box2 { grid-area: 1 / 2 / 2 / 3; }
      .box3 { grid-area: 1 / 3 / 2 / 4; }
      .box4 { grid-area: 2 / 1 / 3 / 2; }
      .box5 { grid-area: 2 / 2 / 3 / 3; }
      .box6 { grid-area: 2 / 3 / 3 / 4; }
      .black-box1 { grid-area: 1 / 1 / 2 / 2; }
      .black-box2 { grid-area: 1 / 2 / 2 / 3; }
      .black-box3 { grid-area: 1 / 3 / 2 / 4; }
      .black-box4 { grid-area: 2 / 1 / 3 / 2; }
      .black-box5 { grid-area: 2 / 2 / 3 / 3; }
      .black-box6 { grid-area: 2 / 3 / 3 / 4; }
      .grey-box1 { grid-area: 1 / 1 / 2 / 2; }
      .grey-box2 { grid-area: 1 / 2 / 2 / 3; }
      .grey-box3 { grid-area: 1 / 3 / 2 / 4; }
      .grey-box4 { grid-area: 2 / 1 / 3 / 2; }
      .grey-box5 { grid-area: 2 / 2 / 3 / 3; }
      .grey-box6 { grid-area: 2 / 3 / 3 / 4; }
      .white-box1 { grid-area: 1 / 1 / 2 / 2; }
      .white-box2 { grid-area: 1 / 2 / 2 / 3; }
      .white-box3 { grid-area: 1 / 3 / 2 / 4; }
      .white-box4 { grid-area: 2 / 1 / 3 / 2; }
      .white-box5 { grid-area: 2 / 2 / 3 / 3; }
      .white-box6 { grid-area: 2 / 3 / 3 / 4; }
      .auto-box1 { grid-area: 1 / 1 / 2 / 2; }
      .auto-box2 { grid-area: 1 / 2 / 2 / 3; }
      .auto-box3 { grid-area: 1 / 3 / 2 / 4; }
      .auto-box4 { grid-area: 2 / 1 / 3 / 2; }
      .auto-box5 { grid-area: 2 / 2 / 3 / 3; }
      .auto-box6 { grid-area: 2 / 3 / 3 / 4; }
      .grid-container {
      display: grid;
      grid-auto-columns: 50px;
      grid-gap: 10px;
      background-color: #555;
      padding: 10px;
      }
      .grid-container > div {
      background-color: #ccc;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
      .black-container {
      display: grid;
      grid-auto-columns: 100px;
      grid-gap: 10px;
      background-color: #000;
      padding: 10px;
      }
      .black-container > div {
      background-color: #ccc;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
      .grey-container {
      display: grid;
      grid-auto-columns: max-content;
      grid-gap: 10px;
      background-color: #ccc;
      padding: 10px;
      }
      .grey-container > div {
      background-color: #555;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
      .white-container {
      display: grid;
      grid-auto-columns: min-content;
      grid-gap: 10px;
      background-color: #ccc;
      padding: 10px;
      }
      .white-container > div {
      background-color: #fff;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
      .auto-container {
      display: grid;
      grid-auto-columns: auto;
      grid-gap: 10px;
      background-color: #ccc;
      padding: 10px;
      }
      .auto-container > div {
      background-color: #999;
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Exemple de la propriété grid-auto-columns</h2>
    <p>Utilisez la propriété grid-auto-columns pour définir une taille initiale (largeur) pour toutes les colonnes.</p>
    <h3>50 pixels</h3>
    <div class="grid-container">
      <div class="box1">1</div>
      <div class="box2">2</div>
      <div class="box3">3</div>
      <div class="box4">4</div>
      <div class="box5">5</div>
      <div class="box6">6</div>
    </div>
    <h3>100 pixels</h3>
    <div class="black-container">
      <div class="black-box1">1</div>
      <div class="black-box2">2</div>
      <div class="black-box3">3</div>
      <div class="black-box4">4</div>
      <div class="black-box5">5</div>
      <div class="black-box6">6</div>
    </div>
    <h3>max-content</h3>
    <div class="grey-container">
      <div class="grey-box1">1</div>
      <div class="grey-box2">2</div>
      <div class="grey-box3">3</div>
      <div class="grey-box4">4</div>
      <div class="grey-box5">5</div>
      <div class="grey-box6">6</div>
    </div>
    <h3>min-content</h3>
    <div class="white-container">
      <div class="white-box1">1</div>
      <div class="white-box2">2</div>
      <div class="white-box3">3</div>
      <div class="white-box4">4</div>
      <div class="white-box5">5</div>
      <div class="white-box6">6</div>
    </div>
    <h3>auto</h3>
    <div class="auto-container">
      <div class="auto-box1">1</div>
      <div class="auto-box2">2</div>
      <div class="auto-box3">3</div>
      <div class="auto-box4">4</div>
      <div class="auto-box5">5</div>
      <div class="auto-box6">6</div>
    </div>
  </body>
</html>

Valeurs

Valeur Description
auto La taille des colonnes occupe la taille du conteneur. C'est la valeur initiale de cette propriété.
max-content La taille de chaque colonne dépend du plus grand élément de la colonne.
min-content La taille de chaque colonne dépend du plus petit élément de la colonne.
minmax(min.max) L'intervalle de la taille est supérieur ou égal à "min" et inférieur ou égal à "max".
length La taille des colonnes est spécifiée par la valeur lenght.
% La taille des colonnes est spécifiée en pourcentages.
initial Fait la propriété utiliser sa valeur initiale.
inherit Hérite la propriété de son élément parent.

Support de Navigateurs

57+ 16+ 70+ 10.1+ 44+


Trouvez-vous cela utile?

Articles Associées