This is my code:
body {
padding-top: 20px;
text-align: center;
background-color:black;
}
h1 {
display: inline-block;
background: white;
}
h1 {
font-size: 30px
}
p {
background: yellow;
}
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.content {
width: 20%;
background-color: red;
padding: 20px; margin:10px;
}
<div class="container">
<div class="content">
<h1>Box 1</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
</div>
<div class="content">
<h1>Box 2</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
</div>
<div class="content">
<h1>Box 3</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
</div>
<div class="content">
<h1>Box 4</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
</p>
</div>
<div class="content">
<h1>Box 5</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
</div>
</div>
However, I have two problems with my code:
The box sizes are unequal in height: But why does the second row not have the same height as the first row? I thought that the flex-wrap would also mean that the boxes in all other wrapped rows are of equal height (i.e. the height of the biggest box in the Flexbox parent which is Box 3) What can I change in order to make all boxes the same size as the biggest box - regardless of wrapping?
The text boxes are unequal in height: In order to create a more pleasing aesthetic, I would like to have the yellow background of the text match in every box, i.e. I want to have lots of yellow free space beneath Box 1 and 2 so that the yellow boxes are automatically as high as Box 3. How can I accomplish that?