I want all items to be equally wide (as wide as the widest item) and wrap to the next line when there is no more space. My following code is however not working because the width of the items is just being set to 1/7th of the container instead of the width of the content inside it. How can I fix?
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: rgba(255, 0, 0, 0.3);
max-width: 25rem;
gap: 1rem;
padding: 1rem;
}
.flex-item {
flex: 1 1 auto;
width: 0;
box-sizing: border-box;
background: rgba(0, 0, 255, 0.3);
}
<div class='flex-container'>
<div class='flex-item'>A</div>
<div class='flex-item'>AB</div>
<div class='flex-item'>ABC</div>
<div class='flex-item'>ABCD</div>
<div class='flex-item'>ABCDE</div>
<div class='flex-item'>ABCDEF</div>
<div class='flex-item'>ABCDEFG</div>
</div>