I have two <input>
elements -- one is type text
the other is type date
. When they are on a line by themselves, they both grow to the same width. However, if I move them both inside a div
with display:flex
, suddenly the <input type="date" />
becomes smaller than the other.
How can I ensure that the both element widths get calculated the same when they are free to grow (i.e. no hard-coded width)?
* {
box-sizing: border-box;
-webkit-box-sizing : border-box;
-moz-box-sizing: border-box;
}
body{
display:flex;
flex-grow:1;
flex-direction: column;
height: 95vh;
}
.form{
display:flex;
flex-direction: column;
width: 600px;
}
.input-row{
display:flex;
}
.input-group{
display:flex;
flex-direction: column;
flex-grow: 1;
margin-bottom: 10px;
}
input {
display: inline-block;
}
input, select {
padding: .4em;
}
input[type="date"]{
padding: .3em;
}
.comment{
font-size: .8em;
margin: 15px 0px;
color: blue;
}
<div class="form">
<span class="comment">Notice how both text and date expand to the same width when they're alone on the line.</span>
<div class="input-group">
<label>Text</label>
<input type = "text" />
</div>
<div class="input-group">
<label>Date</label>
<input type="date" />
</div>
<span class="comment">Notice how Date is smaller than Text when combined on a single line</span>
<div class="input-row">
<div class="input-group">
<label>Text</label>
<input type = "text" />
</div>
<div class="input-group">
<label>Date</label>
<input type="date" />
</div>
</div>
<div class="input-row">
<div class="input-group">
<label>Text</label>
<input type = "text" />
</div>
<div class="input-group">
<label>Text2</label>
<input type="text" />
</div>
</div>
</div>