Grid system
Anyone know if this is possible?
I want to make a grid system. Now it is not possible to get them right. Photo 1 is what it currently looks like, but it. should be like photo 2.
So everything should fit together
This is my css
This is my html
Hopefully someone can help me?
7 Replies
To achieve the "masonry" design of the second image you will either have to create multiple grid rows and tell each box to extend across different numbers of rows or, possibly simpler, use columns rather than grid on the parent container.
alternatively, in this specific case you can use flex if you don't mind the order being a little odd
you can set the direction to column, and turn on flex wrap. Usually it's not good enough because it's going to order things like this:
while you usually want
but in this case I think you can just reorder the markup and not worry about it
I was trying to see how this might work but the realized that you must be suggesting applying the flex to the grid children elements, the ones that currently have the "col-grid-6" class. Is that right?
I hadn't looked that far yet, I just know you can fake a masonry layout like that
looking now, I'd put it on
.grid
well, rename it, but stillI would do this with columns, the downside being the ordering issue that you have mentioned, but that can probably be resolved in the markup.
I gona try tomorow! thx guys
thanks @Chris this works for the 2 columns but I would like to do something that the class .grid is The 'container'. And so I can determine how wide it is based on the other class .col-grid-6. So .col-grid-6 is 50% and for example .col-grid-4 is 33%
so column 2 works if I always have 2 columns, but not if I want it differently
In that case you will probably have to define row heights and tell each "box" how many rows it should cover. It might be possible with flex 🤔
The idea of a masonry grid is something that is being discussed by the CSS developer people (not the correct term, I know). Kevin recently released a video regarding this topic https://www.youtube.com/watch?v=azs0xtt_tJc
Kevin Powell
YouTube
What would you call this layout?
Read the full artcile here 👉 https://webkit.org/blog/15269/help-us-invent-masonry-layouts-for-css-grid-level-3/ and Chrome has put out an alternate proposal I didn't mention in the video, which has the opposite point of view: https://developer.chrome.com/blog/masonry
🔗 Links
✅ The full article: https://webkit.org/blog/15269/help-us-invent-mason...