Greediness with unspecified width of flex blocks in CSS
If flex elements do not have a specified width, then this width will be generated based on the content:
<div class="parent">
<div class="child elem1">text text text</div>
<div class="child elem2">text</div>
</div>
.parent {
display: flex;
width: 300px;
height: 200px;
border: 1px solid red;
}
.child {
height: 50px;
border: 1px solid green;
}
:
If you set greediness for such elements, the free space will be added to the width formed by the text:
<div class="parent">
<div class="child elem1">text text text</div>
<div class="child elem2">text</div>
</div>
.parent {
display: flex;
width: 300px;
height: 200px;
border: 1px solid red;
}
.child {
height: 50px;
border: 1px solid green;
}
.elem1 {
flex-grow: 1;
}
.elem2 {
flex-grow: 1;
}
: