In this example, you can switch between three different display
property values, including flex
, grid
, and block
. You can also switch between the different values for align-content
.
HTML
<section>
<div class="olive">Olive</div>
<div class="coral">Coral</div>
<div class="deepskyblue">Deep<br />sky<br />blue</div>
<div class="orchid">Orchid</div>
<div class="slateblue">Slateblue</div>
<div class="maroon">Maroon</div>
</section>
CSS
section {
border: solid 1.5px tomato;
height: 300px;
width: 300px;
flex-wrap: wrap; /* used by flex only */
gap: 0.2rem; /* not used by block */
}
.olive {
background-color: olive;
}
.coral {
background-color: coral;
}
.deepskyblue {
background-color: deepskyblue;
}
.orchid {
background-color: orchid;
}
.slateblue {
background-color: slateblue;
color: white;
}
.maroon {
background-color: maroon;
color: white;
}
Result
Try changing the display
value and the align-content
value.
In block layout, child elements are treated as a single element, meaning space-between
, space-around
, and space-evenly
behave differently.