-
Notifications
You must be signed in to change notification settings - Fork 707
[css-grid] Request: an easy way to set adjusted-to-fit repeated track sizes #3767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This seems reasonable to me. Randomly thought about |
It seems simpler (and more flexible) to just add an optional third param as the "ideal length" to repeat(auto-fit/fill, <track-list>, <fixed-breadth>);
repeat(auto-fill, 1fr, 100px); (Assuming you want an |
Would #2611 solve your usecase? Something like grid-template-columns: repeat(auto-fit, minmax(1fr, <length>)); and possibly Edit: it seems that the tracks would be limited to |
@Loirooriol It depends on how that is spec'd to behave. The discussion in #2611 doesn't cover how a min value of If the auto-fit basis for |
@MatsPalmgren That's definitely one idea: it allows you to still have the full flexibility of the To make that separation clearer, maybe the repeat(auto-fit(<fixed-breadth>), <track-list>);
repeat(auto-fill(<fixed-breadth>), <track-list>);
repeat(auto-fit(100px), 1fr);
/* fit as many columns as would be possible at 100px width,
then adjust each to equal width so long as none are less than min-content */
repeat(auto-fit(100px), minmax(0,1fr));
/* ignore the min-content requirement to make them strictly equal */ |
I'd like an easy & intuitive way to specify the following grid layout pattern:
Set an ideal track size (column width or row height), and then have automatic repeats where the actual track size are adjusted to neatly fit the container, without overflowing or leaving gaps.
In other words, I want column widths that are the same as I'd get for a multi-col layout with:
(I'm using columns in the example for comparison to multi-col, but of course this should also work for auto-repeat rows when the block size of the container is constrained.)
You can get almost all the way there, currently, by saying for your grid container:
...but that forces the
<length>
to be treated as a strict minimum track size, causing overflow if the container width is smaller than that. To override the minimum, you either need to wrap theminmax()
function in amin()
function (when that is eventually supported cross-browser) or use a media query (assuming the container width that triggers overflow can be reliably calculated from the document width).With a
min()
constraint added, you're looking at the following CSS:which is:
Some potential syntaxes for making that long, complex command simpler:
PS, If you think there is existing CSS that can handle this more simply, please give it a go:
flex: 1 <length>
on the child items creates the behavior we want, except that the last line doesn't line up into nice columns): https://codepen.io/AmeliaBR/pen/vPwGMb?editors=1100More examples/discussion courtesy of Amber Weinberg-Jones's tweet:
https://mobile.twitter.com/amberweinberg/status/1110584873167785985
The text was updated successfully, but these errors were encountered: