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
[css-grid] grid-template-width and grid-template-height #9182
Comments
#9325 allows clamping the number of repetitions, but it wouldn't help here since 1fr would still resolve using the entire element. I don't like your proposal because it's grid-specific, but a similar thing could be wanted in e.g. flex or block. Also, the "will be ignored if there's a conflict with the values of grid-template-columns/rows" isn't much well defined, e.g. I think the right solution is #2406: <style>
.grid {
background-color: #00BD79;
}
.grid::contents {
max-width: 1400px;
margin: auto;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
gap: 20px;
}
</style>
<div class="grid">
<!-- grid elements here -->
</div> |
I can see this problem with .element {
width: 300px;
}
.element::contents {
display: block;
width: 400px;
} I think a new single property with a good definition and narrow scope is better than creating a new element with limitless combinations.
That's fair. Maybe changing the name to be more generic? For example |
Sure, but it's not a problem, because it's an entirely independent (pseudo-)element, so everything is well defined it allows controlling the behavior separately. The problem with
On the opposite, I think that a property that would probably require duplicating lots of the existing ones (like having a variant of |
This is not a problem because For example: .item {
display: grid;
grid-template-columns: 300px;
justify-content: center;
} is exactly like: .item {
display: grid;
grid-template-columns: 1fr;
grid-template-width: 300px;
justify-content: center;
} In both cases, |
The total size of the grid template depends on different things. For example, if all columns have fixed sizes, the template grid is the sum of all columns:
If some columns use
fr
units, the grid will take all available space, so the total width is the same as the element width:Sometimes we want to create a flexible grid, using
fr
values, but without taking all available space. Let's see the following example:This is a website where the content takes a maximum width of 1400px. To create this grid, we need two elements, one for the green background and other to distribute the elements:
It would be great if this could be done with only one element using the new property
grid-template-width
to limit the total width of the grid:The
grid-template-height
property would have the same behavior but applied to the height of the grid.This new property will be ignored if there's a conflict with the values of grid-template-columns, or grid-template-rows. For example:
The text was updated successfully, but these errors were encountered: