JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</div>
<p style="text-align: center">CSS is not aware of children wrapping. Hence, the container doesn't recalculate its width to tightly fit narrower content.</p>
CSS
ul {
display: flex;
flex-wrap: wrap;
margin: 0;
padding: 0;
border: 5px solid green;
}
li {
list-style-type: none;
border: 1px solid gray;
margin: 15px;
padding: 5px;
width: 200px;
text-align: center;
}