Home > AI > Language > CSS >

justify-content: center

.container {
  justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right ... + safe | unsafe;
}
flex items within a flex container demonstrating the different spacing options

Topic 1: the relationship betwwen justify-content and align-items:

A containing element with another box centered inside it.

Example:

<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <div class="box">
      <div></div>
    </div>

    <style>
      .box {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100vw;
        height: 100vh;
        background: blue;
      }

      .box div {
        width: 100px;
        height: 100px;
        background: red;
      }
    </style>
  </body>
</html>

Leave a Reply