Vertical Alignment of Text

How can I get the text in the green box to align in the middle of the box? My vertical-align: middle doesn’t do it.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .container {
      width: 600px;
      height: 800px;
      border: 4px solid black;
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: flex-start;
      text-align: center;
    }

    .orange {
      height: 80px;
      width: 80px;
      background: orange;
      
    }

    .green {
      height: 110px;
      width: 110px;
      background: green;
      color: white;
      vertical-align: middle
    }

    .red {
      height: 140px;
      width: 140px;
      background: red;
      
      color:rgb(253, 249, 1)
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="orange">orange</div>
    <div class="green">green</div>
    <div class="red">red</div>
  </div>
</body>

</html>

Flex-box is good for alignment, make the green box a flex container then justify content and align items:

.green {
      height: 110px;
      width: 110px;
      background: green;
      color: white;
      display: flex;
      justify-content:center;
      align-items: center;
}

Thanks for that most useful tip. I didn’t know that once the container was made a flex, that you could do the same to the elements in the container. Obviously you can because it does work!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.