0

I have a CSS grid layout, where I would like to add a margin to each even column. The :nth-column pseudo-class would be nice but won’t be supported anytime soon.

Are there any polyfills I could use or do I have to write my own?

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Afterlame
  • 1,188
  • 2
  • 13
  • 32
  • You don't want to polyfill the grid-structural pseudo-classes if you want to select elements by their position in a *CSS grid layout*. Those pseudo-classes were not designed and are not intended for that purpose, and attempting to polyfill them to do something else will cause conflicts with browsers in the future. See [this answer](https://stackoverflow.com/questions/44162286/are-there-selectors-that-target-elements-in-certain-grid-positions/44162595#44162595). If you must implement a selector, implement a custom selector and know that it is non-standard. – BoltClock Aug 18 '17 at 09:27
  • Oh okay, I missed their purpose then … what should they be used for? Implementing a custom selector is not necessary. The offset is not critical for the layout, so I would avoid huge workarounds to implement it. – Afterlame Aug 18 '17 at 09:32
  • Ah okay, you are referring to the CSS grid layout. So those selectors are table-layout specific? – Afterlame Aug 18 '17 at 09:37
  • 1
    Yes; at least in HTML, tables are the only thing that have grid-structural semantics. Selectors were never designed to match elements by their styles since using them in CSS would be problematic. – BoltClock Aug 18 '17 at 09:38
  • ah okay, thanks for clearing this up. – Afterlame Aug 18 '17 at 09:40

1 Answers1

0

Just found out about sel, but if there is anything more lightweight (feature specific polyfills), that would be nice.

Afterlame
  • 1,188
  • 2
  • 13
  • 32