When you create a flex container (display: flex
or display: inline-flex
), it comes with several default settings. Among them are:
flex-direction: row
- flex items will align horizontally
justify-content: flex-start
- flex items will stack at the start of the line
flex-wrap: nowrap
- flex items are forced to stay in a single line
flex-shrink: 1
- flex items are allowed to shrink
Note the last two settings.
Your three divs are forced to remain in a single line. Hence, their combined width is limited to the width of the container.
Also, they are allowed to shrink, which prevents them from overflowing the container. This also limits their width.
To apply whatever width you want to each flex item you can override these initial settings with:
flex-wrap: wrap
- now there's more space because flex items can break to new lines
flex-shrink: 0
- now there's more space because flex items will not shrink and can overflow their container if necessary
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…