Show HN: Magic Grid – A simple JavaScript library for dynamic grid layouts
github.com
github.com
As mentioned, Masonry[1] is the other famous library for doing this. Magic Grid also has a Vue port[2] if you're into that.
[EDIT] - PR just got merged, explanation of this stuff is on the Github README now
[0]: https://github.com/rachelandrew/cssgrid-ama/issues/19
https://jsfiddle.net/cbjzped2/
The problem with that is that the grid rows are determined dynamically:
.item.v2 {
grid-row: span 2;
}
.item.v3 {
grid-row: span 3;
}
.item.v4 {
grid-row: span 4;
}
.item.h2 {
grid-column: span 2;
}
I'd much rather drop in a library like MagicGrid or Masonry and deal with it from there, to be honest, instead of trying to hack grid to do it. I think grid could be extended to handle this kind of design but until it is...So do you mean this is a less complex, more sane way, or did you mean it enables things that couldn’t be done with grid/flex?
Of course sanity is good but it’s an important distinction, say if a simple scenario could avoid a library dep without much extra complexity.
Some of the auto sizing features of grid make it seem like it could work but I haven't seen too many examples, and rachelandrews saying "it's not built for that" is more than enough to discourage me from trying to hack around it.
Fully responsive turned out to be a lot harder than I thought it would be due to lots of rabbit holes, but the algorithm was fairly straightforward. My first approach was to try CSS Flex and Grid, but they didn't cut the mustard since they're not really designed for this sort of thing. I then found CSS Columns and had that working, but it proved too unstable for production use with issues with the sort order of items, wrapping across columns, and cross-browser support.
I ended up building our own library: https://github.com/heydovetail/react-masonry-responsive
There's a nice brief writeup about using CSS for masonry layout here: https://regisphilibert.com/blog/2017/12/pure-css-masonry-lay...
For example, consider a bookshelf design where the books are the items and each row has an element underneath it (the element would itself be composed of say 3 images for left and right ends plus the middle)
afaik that's not possible with CSS grid either since grid doesn't have an `nth-row` selector
Anyone know of a good grid layout library/framework.
With grid i don't mean the css syntax version but the actual visual design grid that gives you something like:
It really looked like you would have been referrring to the text overlapping multiple columns, is that not related to what you meant?
Something like this https://www.pcscoreboards.com/footballscoreboardpro/scoreboa...
Notice the red 8 seems to need to overlap between rows.
All CSS grid properties are defined in terms of grid "lines", not cells. If you have a grid of 2x2 cells, there are actually 3 vertical lines and 3 horizontal lines:
1 2 3
1 ┌─┬─┐
2 ├─┼─┤
3 └─┴─┘
"grid-column-start: x" means "this area starts the x vertical line""grid-column-end: y" means "this area ends at the y vertical line"
As you can see, there is no possible ambiguity here on whether you mean "inclusive" or "exclusive" like there would be if you referred to cells (which is why you had this question). That's the reason they chose to go with the "lines" model.
> In fact where there is a ressource for understanding css logic on the internet?
Usually each CSS spec has a rationale and some introduction to the "why" and the "thinking model" of the spec. For CSS grid you may look at [1].
It isn't as optimal a layout system as you can get with javascript but generally so long as all elements are at least half the height of other members of a row it doesn't look offensively bad. And there is room for more sophisticated layout algorithms in the future.
And it generally isn't that hard to pad grid items to be multiples of a common height so they can organically fill consistently.