Is a global grid with 'auto wrapping" subgrid possible?

codepen: https://codepen.io/elmcrest/pen/ExMLeLW I'm experimenting with a new layout trying to get a global grid to work with multiple subgrids. I'm not sure if the description makes that much sense so I just try to explain everything and hope for the best. when there's enough space, the four class="keyword" elements (just keywords as follows) just stay in a single row. when the viewport gets more narrow they should wrap just if it would be a flex container with auto-wrap. but here the four keywords are in a subgrid and consume the outer main-grid's columns and rows, so it's possible in other places to match the grid, f.e. a heading or whatever you like. In the example the "p" in the heading aligns perfectly with the "P" for Python, or "R", "D" and "J" depending on the viewport width. I couldn't find a better or cleaner solution yet, if there's even one? So that's the question - is there a better way to do this? disclaimer: this is an experiment and doesn't aim for production quality robustness and quality...
30 Replies
b1mind
b1mind11mo ago
mmm interesting I'm not sure I get the point of the pseudo elements being a "gap" when we can just use gap property? Have you seen Kevins video on grid-template line names?
elmcrest
elmcrestOP11mo ago
nope, not yet ... actually just started with this course and joined here but, yeah, you're right, nice! I didn't like it in first place
b1mind
b1mind11mo ago
I've been playing more with something like this > https://youtu.be/cf-J4ffMBfo?si=gIsVay4ZNBju9Npa, because we had to wait so long on subgrid. So I would do something similar in subgrid too though.
Kevin Powell
YouTube
Probably the most underrated (and useful) CSS feature
Looking to step up your CSS games? I’ve got free and premium courses to help you out! 👉 https://kevinpowell.co/courses?utm_campaign=general&utm_source=youtube&utm_medium=named-grid-lines I don’t think I’m alone in not using named grid lines very often. They are something I dismissed early on because I figured line numbers were good enough and f...
elmcrest
elmcrestOP11mo ago
ah, wait - with ::after I could support gaps with different heights based on (surrounding?) line-heights ... but I have no idea if that's a "valid" assumption from a Designer's perspective - that's above my understanding 😄
b1mind
b1mind11mo ago
I mean I like that its unique honestly ... Nothing wrong with having a different method long as it makes sense, otherwise use the tools we have.
elmcrest
elmcrestOP11mo ago
holy 🐮 😄
b1mind
b1mind11mo ago
I was asking genuinely to see if you had a specific reason for using ::after for the spacing.
elmcrest
elmcrestOP11mo ago
I started with it but discovered the "line-height" property along the way - it was more like "at least this would be possible" ... so I guess I'll get rid of it
b1mind
b1mind11mo ago
Well so common patters are to have margin-top or ya just gap in the grid
elmcrest
elmcrestOP11mo ago
yeah, gap I try to get away without any margins but paddings will be needed I guess but wait row-gap doesn't work :think: is that Kevin thinking?
b1mind
b1mind11mo ago
few things you wanna watch out for too you are using <span> then naming it paragraph xD just use <p> semantics > all
elmcrest
elmcrestOP11mo ago
yeah row-gap doesn't work since I'm at time consuming more than a single row with a single subgrid
b1mind
b1mind11mo ago
I would limit the columns and rows to only be something that gets content, unless you need to overlap
elmcrest
elmcrestOP11mo ago
yeah, that was just more convenient compared to setting margin:0 on p ... 😄
b1mind
b1mind11mo ago
its not though you have to type more (naming the class and adding stuff) and using the wrong html cause span is a inline-block
elmcrest
elmcrestOP11mo ago
you mean grid-row: span 12?
b1mind
b1mind11mo ago
yea don't do that 12 grid stuff
elmcrest
elmcrestOP11mo ago
but then I'll need javascript
b1mind
b1mind11mo ago
For what?
elmcrest
elmcrestOP11mo ago
I was hoping grid-row: span auto was possible, but it's either not in the spec or just not working - the subgrid doesn't allocate more rows from the parent grid even if it needs to so you need to manually expand span n as needed, depending on the number of children in that subgrid
b1mind
b1mind11mo ago
I mean I don't really get the need for subgrid here either though 😄
elmcrest
elmcrestOP11mo ago
yeah, it's more about to explore the limitations than actually using it
b1mind
b1mind11mo ago
Yea for sure
elmcrest
elmcrestOP11mo ago
I was running into not having subgrid roughly 5-7 years ago ... when grid was new but to solve this, probably today most straight forward would be with a flex container instead of the subgrid and making sure that column size and child width match with css custom properties ... they're great ok, calling it a day - nice to meet you! 🙂
b1mind
b1mind11mo ago
na still grid but you don't need to get some complicated around it 😄 Watch that video I linked it might give you some ideas in it he is using :inherit but you can just use subgrid.
elmcrest
elmcrestOP11mo ago
Yeah that‘s my bedtime task 😂 Oh that‘s great. Didn’t realize the potential of named lines until now, thx for sharing. ok, from a first try there are some gains with named lines - f.e. it's easy to have empty cells - but there's now a major drawback, I have to assign a child a class to point it to the right space in the layout - which breaks my semantic approach (if that makes sense) ... in the example there is the combined element of a keyword having an icon and a name. with my initial example I can change the order in HTML without having to touch the CSS, with named lines that's not possible anymore I think I could use of course :nth-child somehow now, we'll see
elmcrest
elmcrestOP11mo ago
but this results then in columns not being drawn to the bottom, if there are less children, see screenshot:
No description
elmcrest
elmcrestOP11mo ago
bottom right corner - the column on the right should have background color just as the one on the left
elmcrest
elmcrestOP11mo ago
with empty elements, cells are rendered again. so I guess with nth-child() you kind of reverse the approach where you can have empty cells (compared to as mentioned above when given children an identifier class)
No description
elmcrest
elmcrestOP11mo ago
so, anyone who's interested - I solved it now with repeat auto-fit and it works quite nice I'd say ... I'm still planning to iron out a consistent line-height or row height for the last layout polish, but anyways... have a look at https://raesener.de and let me know if I should paste the html file here (the whole website a single file)
Want results from more Discord servers?
Add your server