Hacker News new | ask | show | jobs
by underwater 1629 days ago
A margin is contextual, so a reusable component shouldn't have them.

It's a shame that CSS doesn't allow the parent element to define how spacing around the child elements should work.

4 comments

I thought you could do that with eg.

  parent > * {
  ...
  }
There might be things missing to achieve whatever result you desire, but CSS does allow a parent element to define how spacing (and any other styling) works for child elements.
We can do this now with flexbox and grid. Spacer component from the article can be implemented with https://developer.mozilla.org/en-US/docs/Web/CSS/gap
> It's a shame that CSS doesn't allow the parent element to define how spacing around the child elements should work.

It really would be a shame if CSS didn’t have child selectors, and if they weren’t more specific than bare selectors.

You can do it with selectors, also with flexbox and the gap property.