I want to add the items in the container from top to bottom and left to right to display items in several columns. Here is the code what I'm working on.
#container {
display: inline-flex;
flex-direction: column;
flex-wrap: wrap;
max-height: 250px;
padding: 10px;
margin: 20px;
background-color: blue;
}
#container .item {
width: 80px;
height: 50px;
background-color: red;
margin: 10px;
}
<div id="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
<div id="container">
<div class="item">1</div>
</div>
When I set the display
property as inline-flex
the container does include only a single column, but not all the columns. If I set the display
property as flex
, the container width is larger than the total width of all the columns.
Here is the image what I need for better understanding.
How can I make container width the same with the content width?