Détail de l'article

Retour à la liste de la page d'accueil Update  Delete

Grid position

Grid Position "items".
Align, justify et place-items en Grid.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Grid Layout</title>
    <style>
      .grid-container {
        box-sizing: border-box;
        margin: 10px auto;
        width: 100%;
        max-width: 640px;
        background-color: rgb(225, 225, 225);
        aspect-ratio: 1 / 1;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(3, 1fr);
        padding: 0.5%;
        gap: 1%;
      }
      .grid-container > div {
        background-color: lightblue;
        padding: 20px;
        border: 1px solid grey;
      }
      h3 {
        margin: 25px auto 0;
        width: 100%;
        max-width: 640px;
      }
      .align-stretch {
        align-items: stretch;
      }
      .align-start {
        align-items: start;
      }
      .align-center {
        align-items: center;
      }
      .align-end {
        align-items: end;
      }
      .justify-stretch {
        justify-items: stretch;
      }
      .justify-start {
        justify-items: start;
      }
      .justify-center {
        justify-items: center;
      }
      .justify-end {
        justify-items: end;
      }
    </style>
    <script>
      // function grille(align, justify) {
      grille = (align, justify) => {
        document.write(
          '<div class="grid-container align-' +
            align +
            " justify-" +
            justify +
            '">'
        );
        for (var i = 1; i <= 9; i++) {
          document.write("<div>" + i + "</div>");
        }
        document.write("</div>");
      };
    </script>
  </head>
  <body>
    <!-- stretch stretch -->
    <h3>Défaut</h3>
    <script>
      grille("stretch", "stretch");
    </script>

    <!-- start stretch -->
    <h3>
      align-items: start; (Axe vertical), justify-items: stretch; (Axe
      horizontal), <br />place-items: start stretch; (Axe vertical, Axe
      horizontal)
    </h3>
    <script>
      grille("start", "stretch");
    </script>
    <!-- start start -->
    <h3>
      align-items: start; (Axe vertical), justify-items: start; (Axe
      horizontal), <br />place-items: start; (Axe vertical, Axe horizontal)
    </h3>
    <script>
      grille("start", "start");
    </script>
    <!-- start center -->
    <h3>start et center (Axe vertical et Axe horizontal)</h3>
    <script>
      grille("start", "center");
    </script>
    <!-- start end -->
    <h3>start end</h3>
    <script>
      grille("start", "end");
    </script>

    <!-- center stretch -->
    <h3>center stretch</h3>
    <script>
      grille("center", "stretch");
    </script>
    <!-- center start -->
    <h3>center start</h3>
    <script>
      grille("center", "start");
    </script>
    <!-- center center -->
    <h3>center</h3>
    <script>
      grille("center", "center");
    </script>
    <!-- center end -->
    <h3>center end</h3>
    <script>
      grille("center", "end");
    </script>

    <!-- end stretch -->
    <h3>end stretch</h3>
    <script>
      grille("end", "stretch");
    </script>
    <!-- end start -->
    <h3>end start</h3>
    <script>
      grille("end", "start");
    </script>
    <!-- end center -->
    <h3>end center</h3>
    <script>
      grille("end", "center");
    </script>
    <!-- end end -->
    <h3>end</h3>
    <script>
      grille("end", "end");
    </script>

    <!-- stretch start -->
    <h3>stretch start</h3>
    <script>
      grille("stretch", "start");
    </script>
    <!-- stretch center -->
    <h3>stretch center</h3>
    <script>
      grille("stretch", "center");
    </script>
    <!-- stretch end -->
    <h3>stretch end</h3>
    <script>
      grille("stretch", "end");
    </script>
  </body>
</html>

Détail de l'article