I'm sure calculators are a common project, but I'm really struggling with my use of flexbox here. I have a row class for each calculator button row, and different button sizes. But the last buttons are going down a new line rather than staying in the original line of the row, even though they have enough width.
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.wrapper {
display: flex;
flex-direction: column;
background-color: #0f0f0f;
color: #fff;
width: 400px;
align-content: stretch;
justify-content: space-between;
font-family: Helvetica, Arial, sans-serif;
}
/* ROWS */
.result-row {
width: 100%;
font-family: monospace;
background-color: #0f0f0f;
text-align: right;
}
.row {
width: 100%;
}
/* BUTTONS */
.small {
width: 24.5%;
}
.medium {
width: 49.5%;
}
.large {
width: 74.5%;
}
.button {
border: 0;
border-radius: 0;
}
<div class="wrapper">
<div class="result-row">
0
</div>
<div class="row">
<button class="medium button">C</button>
<button class="small button">←</button>
<button class="small button">÷</button>
</div>
<div class="row">
<button class="small button">7</button>
<button class="small button">8</button>
<button class="small button">9</button>
<button class="small button">X</button>
</div>
<div class="row">
<button class="small button">4</button>
<button class="small button">5</button>
<button class="small button">6</button>
<button class="small button">-</button>
</div>
<div class="row">
<button class="small button">1</button>
<button class="small button">2</button>
<button class="small button">3</button>
<button class="small button">+</button>
</div>
<div class="row">
<button class="large button">0</button>
<button class="small button">=</button>
</div>
</div>
I really don't get what is going on here, I thought that elements within a div couldn't take space in a new "line" with flexbox as long as they had enough space in the container.