Consider a <div>
element that contains <button>
elements:
<div id="box">
<button class="button">1</button>
<button class="button">2</button>
<button class="button">3</button>
...
</div>
I want to fit these elements into a grid pattern, so that
- buttons are of equal dimensions and have a fixed minimum width,
- a maximal amount of buttons is stacked on each row,
- button width is adjusted so that each row is filled completely,
- and this behavior persists when
#box
is resized.
Is there a way to do so using native HTML/CSS features (without using JavaScript)? I tried using the new CSS Flexbox layout:
#box {
display: flex;
width: 500px;
height: 500px;
}
.button {
flex: 1 1 auto;
min-width: 40px;
height: 40px;
}
But this doesn't work..
Thanks for your help!