csswg-drafts icon indicating copy to clipboard operation
csswg-drafts copied to clipboard

[css-grid] Control size of individual gutters independently

Open tabatkins opened this issue 9 years ago • 30 comments

Thread starting here asks for the ability to manually control gutter sizes, so they can be different sizes in different spots.

Right now, the only way to do so is to create it as a track, and then either explicitly avoid placing according to that track, or use a dummy element to fill that track (so auto-placed items avoid it, tho this means they can't span across it either).

There's some suggestions in the thread to extend the grid-gap syntax to allow multiple lengths, interpreted as a repeat pattern.

I'd prefer building this into the grid-template syntax. We already have a place in the syntax for line names, which live in the gutter between the tracks; we can throw in a gap(<length>) function as well, which can only be put between tracks, and which overrides the grid-gap property. (That is, grid-gap sets the default gap size, but you can manually override it.)

tabatkins avatar Jul 28 '17 22:07 tabatkins

My only concern with having this be a part of grid-template is that that requires the explicit naming of the sub objects. The benefit to the pattern based approach is that the contents of the grid can be left "unclassified"

Nokel81 avatar Jul 29 '17 01:07 Nokel81

How does the grid-template syntax address the repetition of a pattern for gutters?

Example - I need 12 columns with a repeating grid-gap pattern of 1rem and 2rem and all my column names remain [col] with all tracks being 1fr.

It would be amazing if we could do something like this without breaking the existing syntax.

.container {
  display: grid;
  /*Because obviously you can't repeat the pattern 11 times or 6 times 
  and say discard the values that go into it. 
  So this repeat function just tries to repeat those length values as long as 
  it can and the first argument isn't a <number>*/
  grid-gap: repeat(1rem, 2rem)  3rem;
}

Here, the grid-column-gap has a pattern of 1rem and 2rem and we get 3rem gutter on rows.

Didn't put a lot of thoughts into parsing so not sure how many things this might break.

praveenpuglia avatar Jul 29 '17 03:07 praveenpuglia

If repeat accepted any number of values I would be completely for this solution as long as using it just for columns of rows was also allowed

Nokel81 avatar Jul 29 '17 04:07 Nokel81

@Nokel81 I updated my answer to include how this new repeat syntax would work

praveenpuglia avatar Jul 29 '17 04:07 praveenpuglia

Another option is to do grid-gap: 1rem 2rem / 3rem. Not sure on the pros and cons of the two options implementation-wise, though.

jhpratt avatar Jul 29 '17 04:07 jhpratt

What do you mean by by the first argument isn't a */?

Nokel81 avatar Jul 29 '17 04:07 Nokel81

@jhpratt I would prefer the have it act like a function so that it is easier to read that it is actually repeating

Nokel81 avatar Jul 29 '17 04:07 Nokel81

@jhpratt - that syntax would be really simple but doesn't convey anything about repetition. A repeat syntax makes it really clear that it has to be repeated.

@Nokel81 Right now, the repeat syntax takes a number as first arguments to figure out how many times it needs to repeat. I skipped the auto-fill keyword which might solve my issue too. So the updated syntax will be like,

grid-gap: 3rem / repeat(auto-fill, 1rem 2rem);

I have now included the slash to make sure we understand the separation for columns and rows. Also, in grid-gap row comes before column so i reversed the order.

praveenpuglia avatar Jul 29 '17 04:07 praveenpuglia

Yes, having auto-fill would be a must because of the auto columns/rows in grids. This is nice and explicit, it does what I believe it should be able to be done and it should work with each direction individually. Lastly, it wouldn't overlap with the current spec because it is a function

Nokel81 avatar Jul 29 '17 04:07 Nokel81

I'd generally prefer having it as part of the grid-gap properties instead of or in addition to grid-template, if only because a complex grid-template setup is something I find people struggle with when I'm teaching this stuff.

We have other stuff that accepts a track listing (eg. grid-auto-rows) so it would be consistent to add that capability here too.

rachelandrew avatar Jul 29 '17 05:07 rachelandrew

@jhpratt I'm perfectly capable of teaching it ;) what I am observing is where people learning get confused. As I think that is useful data in terms of designing stuff people have to use.

rachelandrew avatar Jul 29 '17 05:07 rachelandrew

Adding this to grid-template limits its usage to explicit grids. Though I assume people may also like to apply different gaps to implicit grids.

Non-the-less, the solutions are non-exclusive, i.e. there might be some way to specify the gaps for the explicit grid, which will either be overwritten by grid-gap or grid-gap then defines the gaps for the implicit grid. (Or there might be some switch that controls to what grid-gap applies.

Sebastian

SebastianZ avatar Jul 29 '17 08:07 SebastianZ

One question that needs to be answered is what the auto gap would be if auto-fill is not used. Or would it be required?

Nokel81 avatar Jul 29 '17 19:07 Nokel81

Since I am new to this, how does something like an issue move forward in the discussion of adding it to the standard? I presume it has to go to one of the meetings.

Nokel81 avatar Jul 31 '17 18:07 Nokel81

Discussing it here is the first step, things posted here will be considered when Level 2 is discussed and when something is discussed it gets updated here so you can read the log of the conversation.

rachelandrew avatar Jul 31 '17 18:07 rachelandrew

Is there a known time frame for when specific levels for certain items will be discussed at the contributor level?

Nokel81 avatar Jul 31 '17 18:07 Nokel81

If you are interested in how the CSS WG works then there is information available on that here http://fantasai.inkedblade.net/weblog/2011/inside-csswg/

There aren't specific time frames for specifications, but discussions here are valuable and also demonstrate author interest in a feature.

rachelandrew avatar Jul 31 '17 18:07 rachelandrew

My only concern with having this be a part of grid-template is that that requires the explicit naming of the sub objects. The benefit to the pattern based approach is that the contents of the grid can be left "unclassified"

No, it doesn't; what makes you assume that? Grid-template is the shorthand for the rows/columns/areas properties; are you thinking that it's just for grid-template-areas?

How does the grid-template syntax address the repetition of a pattern for gutters?

It doesn't, but I wasn't aware of a use-case presented that wants a repeated pattern of different gutters between implicit tracks. Tho hm, even if you grouped each "set" of things into a subgrid, you'd still need to establish the gutters on the outer grid, which requires a repeating pattern.

Example - I need 12 columns with a repeating grid-gap pattern of 1rem and 2rem and all my column names remain [col] with all tracks being 1fr.

Ah, this is explicit grid. Then it'd be:

grid-template-columns: repeat(6, [col] 1fr [col gap(1rem)]  1fr [col gap(2rem)] )

As opposed to using an explicit pattern in grid-column-gap:

grid-template-columns: repeat(12, [col] 1fr [col])
grid-column-gap: 1rem 2rem;

tabatkins avatar Aug 03 '17 09:08 tabatkins

Yes I was think of only grid-template-areas though I always seem to use grid-template-columns and grid-template-rows. I still think that the repeat() function in grid-gap is the cleanest solution and should cover all use cases (including individually changing gaps)

Nokel81 avatar Aug 03 '17 14:08 Nokel81

Any new information on when this might be discussed?

I think that the best syntax would be

grid-column-gap: repeat(1 rem, 0 rem, 2 rem, 0 rem);

Where the pattern is repeated.

One problem I do have is that you might want to have a fixed number of fixed widths and then have it repeating.

Here there could be the following syntax:

grid-column-gap: group(fixed(1 rem, 5), repeat(1 rem, 0 rem), fixed(2 rem, 3))

This syntax means the first 5 gaps have a width of 1rem, the last 3 gaps have a width of 2rem and the intervening gaps are switching between a width of 1rem and 0.

With this syntax it can be group(fixed(), repeat()), or group(fixed(), repeat(), fixed()), or group(repeat(), fixed()), or repeat().

If there are less gaps then there are defined in the supplied fixed then the widths from the first are prioritized

Nokel81 avatar Apr 04 '18 00:04 Nokel81