I made a sketch of the layout that I need to make: drawing of the desired layout
My problem is:
how to make articles "4" and "5" position themselves according to the height of the article which is positioned above them, and are not aligned
I tried with these 3 solutions without success:
-
With CSS Grid: CSS grid allows me to position the 5 elements as desired EXCEPT this height alignment problem!
With CSS grid, elements "4" and "5" are aligned regardless of the height of element "2" and "3" -
With CSS Flex: CSS flex allows me to position the 5 elements as desired EXCEPT this height alignment problem!
I got help from this page but even using "align-items" and "align-self" I can’t get items "4" and "5" to rise proportionally to the height of items "2" and "3"
-
MASONRY: I also tried with this method:
This method uses columns in CSS:
.masonry { /* Masonry container */ column-count: 4; column-gap: 1em; } .item { /* Masonry bricks or child elements */ background-color: #eee; display: inline-block; margin: 0 0 1em; width: 100%; }
My problem with this method is that the items display in order vertically inside the columns
This is a news site and the order in which the elements are displayed is very important: the elements must be displayed in order horizontally
3
Answers
Try this:
Without a working snippet of code its hard to debug, but if I’m understanding correctly I would do as follows.
Use the flexbox method that got you most of the way there, but place columns 2 + 3 in a seperate
<div>
this will make columns 4 + 5 align below it starting at the absolute bottom of the largest column of 2 + 3.Alternatively, set a
min-height
to all the columns, making them all align at the same height.I recommend Macy.js. To summon up the docs:
Use the script tag to include:
And add the following code in JavaScript:
Check the docs for more info.