Okay, okay, running out of time. Last thing I wanna talk about masonry layout. Now this was originally a JavaScript layout created by David DiSandro back in 2009. It was all the rage back then, Tumblr uses it, Pinterest uses it, some people call this the Pinterest layout, so good job, Pinterest, I guess. But given its popularity among web designers and developers, this layout method was discussed quite a bit within DCS's working group meetings. And so we have an editor's draft of Grid Level 3 that specifies how masonry can be done natively in the browser with just CSS.
Demo time. So, but like, before CSS masonry, because it's really not very widely supported right now, let's see, yeah, it's only implemented in Firefox behind the flag, so you gotta switch that flag on to be able to see it or even play with my demo right now. So let's say you don't have CSS masonry, we can do something pretty close with the multi-column layout it's just that multi-column has a couple of limitations. Its implementation is also a bit inconsistent across browsers at the moment, in fact.
So I would say that multi-column is more suited for inline content, like lines of text as opposed to like discrete boxes that I'm doing here. I'd say there's inconsistencies because like my break inside is not working here, but if I open this in say, Chrome. Nevermind. So multi-col, when we use it, it's a, how should we put this, it flows, you know, in the block direction and then multi-columns spins back up. So your content is actually flowing top to bottom and then left to right. So if order matters to you, I've numbered these boxes so you can see. Maybe the first couple of things in your grid are important, but you don't want them at the bottom. You can't really control this with multi-column. And what else, you could, if you want to like span your item across columns, you kind of can do that with multi-col, but like as I said, the implementation for multi-column isn't very complete in browsers. So right now all you have is like all, and it kind of looks like this. The breaking, it looks weirdish, a bit buggy, so let's just say multi-col is a third of the way there for Masonry, right? So with CSS Masonry, you can do both directions, the x-axis and the y-axis, because CSS Masonry builds on top of the browser's grid capabilities, and its syntax is pretty similar to how we would use SubGrid, which is part of Grid Level 2. The value of Masonry is applied either to the gridTemplateRows property or the gridTemplateColumns property, depending on the direction that you want to go. For this horizontal direction here, my row heights are defined with template rows here. I put this repeat thing because I'm lazy. And then you can leave the columns free to be masoned. So, essentially, the columns are not lined up as per a normal grid, but they're masonry, whatever the verb is. So, you can definitely do span much better. So because this is horizontal, I'm using gridRow for this. Span two, span three looks kind of nice. Things flow together.
Comments