CSS Flexbox: Use the flex-grow Property to Expand Items
Use the flex-grow Property to Expand Items
The opposite of
flex-shrink is the flex-grow property. Recall that flex-shrink controls the size of the items when the container shrinks. The flex-grow property controls the size of items when the parent container expands.
if one item has a
flex-grow value of 1 and the other has a flex-grow value of 3, the one with the value of 3 will grow three times as much as the other.consider this flex-box containing two boxes box1 and box2 that they do not have width property set .
i add text inside them so they will appear as text wide only.
box1
box2
<style> #box-container { display: flex; height: 300px; } #box-1 { background-color: dodgerblue; height: 200px; } #box-2 { background-color: orangered; height: 200px; } </style> <div id="box-container"> <div id="box-1"></div> <div id="box-2"></div> </div>
now let's use flex-grow in these boxes by adding flex-grow:1 for box1 and flex-grow:2 for box2 and see the result
box1
box2
<style> #box-container { display: flex; height: 300px; } #box-1 { background-color: dodgerblue; height: 200px; flex-grow:1; } #box-2 { background-color: orangered; height: 200px; flex-grow:2; } </style> <div id="box-container"> <div id="box-1"></div> <div id="box-2"></div> </div>
source
Comments
Post a Comment