So I want to create a grid or flexbox layout which looks something like this
.
So all of the data inside each box of the image is dynamic so i am not sure about the size of every box. I am using tailwind css and plain HTML, CSS, JS.
I am creating a parent with class = grid grid-cols-3
and very column has a class = col-span-1
. With this the body is evenly divided into 3 columns but the box of the next line is starting from the end of the longest element of the previous line, i.e. each row height is determined by the longest box of that row. So this is how it is turning out to be
.
I can use class = row-span-2
at the longest box but as said I don’t know what will be the size of each box so I cant use class = row-span-2
.
Here is what I have. Please assume Box x
has all the html and css code for that desired box.
<div class=" grid grid-cols-3 m-12 gap-12 justify-center">
<div id="post" class="max-h-fit h-fit rounded-xl overflow-hidden">
<Box 1/>
</div>
<div id="post2" class="max-h-fit h-fit rounded-xl overflow-hidden">
<Box 2/>
</div>
<div id="post3" class="max-h-fit h-fit rounded-xl overflow-hidden">
<Box 3/>
</div>
<div id="post4" class="max-h-fit h-fit rounded-xl overflow-hidden">
<Box 4/>
</div>
<div id="post5" class="max-h-fit h-fit rounded-xl overflow-hidden">
<Box 5/>
</div>
<div id="pos6t" class="max-h-fit h-fit rounded-xl overflow-hidden">
<Box 6/>
</div>
</div>
3
Answers
What you are looking for is called a Bento grid layout.
You can check some examples here
But coming back to your question, using
CSS Columns
you can achieve the layoutCheck this example:
Result: https://play.tailwindcss.com/7teTDt3LMZ
You can make three grid columns and put elements inside each of those:
The height attributes are added to simulate longer amounts of text or larger sized content, you can remove it and it should still function the same
https://play.tailwindcss.com/XvhOwesYEN
One way is to make a parent div
flex
withflex-row
& wrap the inner threediv
in.