Css grid, column size defined by row height
hey, i know this is topical because of the Css grid event later today.
However i have run into a small wall with a project of mine
Layout
-# i will use pseudocode as example of my layout
Though the issue currently is the repeat(n, 1fr), i want the 1/1 images to be the height of the 16/9, is there a smarter way to do this?
4 Replies
Whilst not related to your question, I am pretty sure that you can simplify those :has selectors to detect where the "n" element is the last-child, something like this:
As to your question, I wonder if you might be better off having 4 columns (in all cases) and in the 3 items rows have the first (or last) element spanning 2 cells 🤔 ?
This wouldn't give you an exactly 16:9 ratio but might create the result that you are after.
The last-child suggestion is a good find! thanks,
As to the 4 col setup, i think that might work but will be different than what i'd expect.
the goal is to be a bit more "dynamic" in the design.
I have now set up a static setup, where the evens are 16fr 9fr 9fr
and the odds 9fr 9fr 16fr for the columns, this is not scalable i think but it works with what i have rn.
Again thanks for the selector optimisation!
@Odinn 🐸 you might wanna explore flex for the layout you are looking for, since you have specific aspect-ratios on mind for each card member, which typically doesn't align quite well with the concept of defined grid columns
Exploiting flex-grow for an Image Gallery
How to build a full-bleed Image Gallery with flexbox.
9elements
Building a combined CSS-aspect-ratio-grid - 9elements
Combining finest craftsmanship with elegant design to ship innovative digital experiences.