Skip to content
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

Don't inherit box-sizing by default #37

Merged
merged 1 commit into from
Dec 23, 2019

Conversation

jamiebuilds
Copy link
Contributor

We previously had * { box-sizing: inherit } in our design system, and chose to remove it because it caused more problems than it fixed. It's rather annoying to need box-sizing: content-box on a specific element, and having to write out:

.target { box-sizing: content-box; }
.target *, .target *::before, .target *::after { box-sizing: border-box; }

And then realizing that's incorrect, it should actually be this:

.target { box-sizing: content-box; }
.target::before, .target::after, .target > *, .target > *::before, .target > *::after  { box-sizing: border-box; }

The only time where having it this way actually helped was the times when a third-party widget expected to have content-box by default (and for some reason didn't set it itself). Which was actually pretty rare occurrence these days, and the box-sizing: inherit doesn't really help because you still need to debug why the layout is all wrong.

But when content-box was needed without being set, it was much easier to either wrap the third party component in a utility class that switched box models, or to just apply the style to the widget that required it with notes on why it was needed.

All in all, we found that * { box-sizing: inherit } does more harm than good. So I thought I'd suggest the change here

We previously had `* { box-sizing: inherit }` in our design system, and chose to remove it because it caused more problems than it fixed. It's rather annoying to need `box-sizing: content-box` in a specific case, and having to write out:

```
.target { box-sizing: content-box; }
.target *, .target *::before, .target *::after { box-sizing: border-box; }
```

And then realizing that's incorrect, it should actually be this:

```
.target { box-sizing: content-box; }
.target::before, .target::after, .target > *, .target > *::before, .target > *::after  { box-sizing: border-box; }
```

The only time where having it this way actually helped was the times when a third-party widget expected to have `content-box` by default (and for some reason didn't set it itself). Which was actually pretty rare occurrence these days, and the `box-sizing: inherit` doesn't really help because you still need to debug why the layout is all wrong.

But when `content-box` was needed without being set, it was much easier to either wrap the third party component in a utility class that switched box models, or to just apply the style to the widget that required it with notes on why it was needed.

All in all, we found that `* { box-sizing: inherit }` does more harm than good. So I thought I'd suggest the change here
@sindresorhus sindresorhus merged commit c9adb78 into sindresorhus:master Dec 23, 2019
@sindresorhus
Copy link
Owner

I agree 👍

@franktopel
Copy link

franktopel commented Jul 12, 2021

I disagree with this decision whole-heartedly. Mixed-mode components imo is a narrow edge case that should not at all be relevant for decision making. If even Paul Irish agrees that inherit approach is superior (I've been working with that for the past 5+ years without a single problem). Please re-consider this design decison. Not using the "improved" version also doesn't match the expectations of experienced CSS developers.

@jamiebuilds
Copy link
Contributor Author

Please re-consider this design decison

If you want to raise points that would trigger reconsideration I think you should do that. But asserting that you have more experience and therefore everyone should listen to you is not useful.

I've worked on design systems at several large tech companies over many years. In that time I've worked with lots of experienced CSS developers and performed lots of large-scale CSS migrations. I opened this issue because I watched the problems of inherited layout play out on those (experienced) teams, and I coordinated migrations away from inherited layout and it had positive results.

Just because you have not personally experienced any issues does not mean that you are smarter or know better, and it does not discount others who have experienced issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants