Please see the code below:
ul {
display: flex;
list-style-type: none;
flex-wrap: wrap;
}
li {
flex-grow: 1;
border: 1px solid;
width: 1000px;
}
<header>
<ul class="child">
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
<li>Friday</li>
</ul>
</header>
Notice the width of 1000px. When I load the page there are five rows as I would expect. If I remove the width
property, then the boxes appear on one row as expected.
Now if I add a width of 1px, then the only change is that all boxes are the same size i.e. 372.28 pixels (not 1px). It appears to me that the behaviour is as follows:
- If any width is added to the flex items that means they can all fit on one row then make sure all boxes are the same size.
- If a width is added to the flex items meaning they cannot all fit on one row then honour the width.
- If a width is not added then the boxes can be any size i.e. the Wednesday box is biggest in this case because Wednesday is the longest word.
Have I understood this correctly and why does the width effect the flex items like this?
I have done my own research and found questions like this: What are the differences between flex-grow and width?. However, I have not found an answer to my question. I have also read about the flex grow property here: https://www.w3.org/TR/2018/CR-css-flexbox-1-20181119/#flex-grow-property