So I have a requirement for 3 blocks of elements to look like this:
No vertical scrolling, only horizontal. To achieve this I thought I could make 3 div.block
with the container display: flex
then have my items inside each .block
flex itself and wrap (note they also need to be top-bottom, left right so flex-direction: column
)
But as you can see in this code (or codepen), when I do that the 3 .block
's widths simply refuse to expand to their content's width, even though the .brick
do wrap they overlap each other, because the .block` just stays as big as a single column.
How can I achieve this? I feel like flex is not the right tool for the containers, but I've tried display: inline-block
and using a table
with 3 td
s which does the exact same thing.
I'm not sure how to get the .container
to increase in width as more content goes in and get the .block
to increase as well.
.container {
width: 600px;
height: 200px;
overflow-x: auto;
overflow-y: hidden;
display: flex;
}
.block {
height: 100%;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.brick {
width: 100px;
height: 50px;
margin: 5px;
}
.brick-red {
background: red;
}
.brick-blue {
background: blue;
}
.brick-orange {
background: orange;
}
<div class="container">
<div class="block">
<div class="brick brick-red"></div>
<div class="brick brick-red"></div>
<div class="brick brick-red"></div>
<div class="brick brick-red"></div>
<div class="brick brick-red"></div>
<div class="brick brick-red"></div>
<div class="brick brick-red"></div>
</div>
<div class="block">
<div class="brick brick-blue"></div>
<div class="brick brick-blue"></div>
<div class="brick brick-blue"></div>
<div class="brick brick-blue"></div>
<div class="brick brick-blue"></div>
</div>
<div class="block">
<div class="brick brick-orange"></div>
<div class="brick brick-orange"></div>
<div class="brick brick-orange"></div>
<div class="brick brick-orange"></div>
<div class="brick brick-orange"></div>
</div>
</div>