rachelandrew / cssgrid-ama

Ask me anything about CSS Grid Layout
328 stars 12 forks source link

Using offsets with auto-positioning #34

Closed sgomes closed 7 years ago

sgomes commented 7 years ago

Hey Rachel!

Thanks for hosting this AMA! Going through other folks' issues has helped me a lot in grokking CSS Grid :)

I'm currently implementing a flexbox-based 12-column layout CSS module, with a progressive enhancement to CSS Grid where available. Going through this exercise really illustrated how much cleaner CSS Grid is; I can simply define gutter and margin sizes and set width: auto on grid items, rather than having complex calc()s everywhere.

However, I've run into something I've found no way to implement: I'd like to offer an 'offset' feature which moves a grid item N columns to the right, while keeping that space empty. You can think of it as a margin on the left side of the grid item:

2-cell spanning boxes. No offset:
+------+ +------+ +------+
|      | |      | |      |
+------+ +------+ +------+

2-cell spanning boxes. Offset of 1 on the centre cell.
+------+     +------+ +------+
|      |     |      | |      |
+------+     +------+ +------+

In flexbox, this is easy to implement; you simply add the length of the offset to the left margin of the grid item (you can easily generate CSS classes with pre-calculated values or use custom properties in your calc()s).

In CSS Grid, however, I haven't found any way of doing this while using auto-positioning. I tried several things:

Is there any way of implementing this offset idea in CSS Grid without inserting a spacer grid item into the DOM? Thanks!

sgomes commented 7 years ago

Also, let me know if a Codepen would help; I can come up with a simplified illustration of the issue that's easier to play around with.

rachelandrew commented 7 years ago

Yes a CodePen would help.

rachelandrew commented 7 years ago

Closing as no further info provided - feel free to reopen with info.