-
Notifications
You must be signed in to change notification settings - Fork 694
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-1] Unpredicable gap positioning with two or more tracks. #7197
Comments
I gave your testcase a quick analysis and everything appears to be working as per the specification. The steps for laying out the grid cells are as follows:
This is what happens in your testcase. So the left and right edges of the grid components are:
The dividers, on the other hand, are primarily placed using percentage positioning. So the first is placed at 50% - 1px, which is 510px - 1px (remember, the container is 1020px wide in my example). That places it at 509px, or its center at 510px, which is right where the first cell and gap meet. The second divider is at 75% - 1px, which is 765px - 1px. That places its left edge at 764px and its center at 765px, which happens to fall just in the middle of the second gap. Essentially, your What you most likely really want is the ability to just set borders on grid items, or else decorations in gaps, rather than having to calculate their positions yourself. These have been (are being) discussed, but as far as I know haven’t yet moved to the stage of being implemented. |
I see. That still seems incorrect though (though it may be correct as per the spec). If I set a grid to be The expected behavior based on the developer documentation would result in the following: a grid of The layout would be:
Given that this is expected behavior, is it not well documented in any developer documentation (MDN or the like), and results in counter intuitive layout behavior. Regardless, this is helpful in that I can at least implement a solution that will work as expected here. |
Gaps are just like additional tracks. So it's like you had The grid algorithm can't know that you actually want the
This is exactly what happens. You can use something like grid-template-columns: calc(50% - 5px) calc(25% - 10px) calc(25% - 5px); Then the 1st gap will be centered at 50%, and the 2nd gap at 75%, but the 2nd and 3rd tracks will have different sizes. Alternatively, consider having an even number of tracks: .app {
grid-template-columns: repeat(4, 1fr);
grid-template-areas: "a a b c";
}
.cell1 { grid-column: a; }
.cell2 { grid-column: b; }
.cell3 { grid-column: c; } For |
@Loirooriol You meant |
For reference, styling gaps is being discussed in #2748 and #6748. Sebastian |
Could this be solved, if we could define the columns like this? column-gap: 10px;
grid-template-columns: calc(50fr + 10px) 25fr 25fr; I also need to align a grid with a css columns, and it is hard |
When defining a grid layout with multiple tracks of fractional units, the alignment of the
grid-gap
property with relation to the overall grid does not align to the expected behavior of the specification.Take for example, a grid layout of
This layout will split each column evenly, resulting in a 5px gap on the left most column, and a 5px gap on the right most column.
However, expand this with a third column as such:
This layout will split the two
25fr
columns evenly, as expected. However, the gap between the50fr
column, and the25fr
column will not be even. Rather, the entirety of the gap will be on the50fr
side of the split.This is a significant issues with more complex layouts, as the gap between children becomes unpredictable, and alignment of any meta-elements becomes impossible.
Spec:
https://www.w3.org/TR/css-grid-1/
Minimum Reproduction:
https://codesandbox.io/s/wild-leftpad-h2f782?file=/index.html
The text was updated successfully, but these errors were encountered: