Arranging Sibling Elements with Flexbox
suggest changeUse Flexbox—not floats—to arrange a one-dimensional row of sibling elements:
<div class="panels">
<section>First panel</section>
<section>Second panel</section>
</div>
.panels {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.panels > * {
flex: 1 1 18rem;
padding: 2rem;
}
Each panel can grow, shrink, and wrap when space is limited. Unlike a float-based layout, the container naturally includes the panels and gap creates spacing without margin bookkeeping.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents