Consider the following example:
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
color: #C0C0C0;
background-color: #202020;
display: flex;
flex-direction: column;
align-items: center;
}
* {
box-sizing: border-box;
}
.col {
display: flex;
flex-direction: column;
}
.row {
display: flex;
flex-direction: row;
background-color: gray
}
.wrap {
flex-wrap: wrap;
}
.align-center {
align-items: center;
}
.justify-center {
justify-content: center;
}
.gap {
gap: 20px;
}
input {
background-color:#202020 ;
border: 1px solid #C0C0C0 ;
border-radius: 5px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
.inputContainer {
max-width: 300px;
width: 100%;
}
.inputContainer > * {
width: 100%;
}
<form class="col gap align-center" style="width: 90vw" action="">
<div class="row wrap gap justify-center">
<div class="col inputContainer">
<label>expands:</label>
<input />
</div>
<div class="col inputContainer">
<label>parent:</label>
<input />
</div>
</div>
<div class="row wrap justify-center">
<div class="col inputContainer">
<label>even if:</label>
<input />
</div>
<div class="col inputContainer">
<label>no gap set:</label>
<input />
</div>
</div>
<div class="row wrap gap justify-center">
<div class="col inputContainer">
<label>alone works:</label>
<input />
</div>
</div>
<div class="row wrap gap justify-center">
<div class="col inputContainer">
<label>also with:</label>
<input style='padding: 0' />
</div>
<div class="col inputContainer">
<label>no padding:</label>
<input style='padding: 0' />
</div>
</div>
</form>
The gray background demonstrates each row dimensions. If the inputs inside have padding on x axis, it expands the parent width, even though box sizing is border box. If there's only one child for the row, it works fine. If no padding set on children, it works fine. If there's padding set, it expands the parent width. Why?