I have two input elements in a flexbox:
<div style="display: flex; width: 200px; background: black; padding: 2px">
<input style="flex: 1" type="text" />
<input style="flex: 1" type="text" />
</div>
(fiddle)
I want those to get the width of 200px evenly shared. They aren't however. Instead, they have have some mysterious default size. They don't listen to min-width
either. They do listen to width
though, so this does the desired thing:
<div style="display: flex; width: 200px; background: black; padding: 2px">
<div style="flex: 1">
<input style="width: 100%" type="text" />
</div>
<div style="flex: 1">
<input style="width: 100%" type="text" />
</div>
</div>
(fiddle)
My question: why? And is this defined somewhere for some reason?
EDIT: This is what Chrome's inspector gives me:
EXTRA QUESTION:
As kukkuz pointed out, min-width
is heeded - but only when the input
s are direct children of the flex container. Otherwise, they again like to be broader:
<div style="display: flex; width: 200px; background: black; padding: 2px">
<div style="background: red; padding: 2px">
<input style="flex: 1; min-width: 0" type="text" />
</div>
<div style="background: red; padding: 2px">
<input style="flex: 1; min-width: 0" type="text" />
</div>
</div>
(fiddle)
Bizarre. Is there a way to make this work without restorting to a width: 100%
?
EDIT:
There is a way without resorting to a width: 100%
: A nested flexbox. (fiddle)
<div style="display: flex; width: 200px; background: black; padding: 2px">
<div style="background: red; padding: 2px; flex: 1; display: flex; min-width: 0">
<input style="min-width: 0; flex: 1" type="text" />
</div>
<div style="background: red; padding: 2px; flex: 1; display: flex; min-width: 0">
<input style="min-width: 0; flex: 1" type="text" />
</div>
</div>