-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Consider a version without forcing box-sizing #48
Comments
Really, Chris Coyier has improved the code that is currently being used in Instead of *, *::before, *::after {
box-sizing: border-box;
} we really should be getting this: html {
box-sizing: border-box;
}
*, *::before, *::after {
box-sizing: inherit;
} I can't explain better than Chris, so please take the time to read his reasoning why this is a much better version: https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ Even Paul Irish, who in 2012 came up with the code you're currently delivering, has agreed and edited his original article to reflect the improvement: https://www.paulirish.com/2012/box-sizing-border-box-ftw/ |
I've created a PR for this improvement. #56 |
This is also an option, but I dont think its always the better one. Both have advantages and disadvantages, for me not inheriting is the better solution. |
Even when inheriting, your use-case can still be supported. Personally, I would just pre-process whatever form of box-sizing normalization is present in a normalization sheet and rip it out, because after having run up against problems with it numerous times, I've come to believe it to be a theoretical ideal but a fallacy in practice... |
The current version was intentional: #37 // @jamiebuilds |
Yeah, I think the advice in css-tricks is only better if you only consider one pattern of building UIs. Compare these two snippets: Islands of widgets: <widget-one/>
<widget-two/>
<widget-three/> Trees of components: <component-one/>
<compontent-two>
<component-three/>
</component-two> Both of these have their place on the web, and really almost every webpage will be a mix of both of these in different places. So given the goals of a generic reset/normalize stylesheet, they should both be considered. The idea behind applying That's great if you're only considering the "islands of widgets" pattern, but then it shifts the burden onto the "trees of components" pattern. And you start getting snippets like this: component {
box-sizing: content-box;
}
component::before, component::after, component > * {
box-sizing: border-box;
} So really we just have a tradeoff here, if we make it easier for "islands of widgets" we make it harder for "trees of components", if we make it easier for "trees of components" we make it harder for "islands of widgets". So the question becomes: Which is the easier mental model for people to apply in the real world?
That's it, they are done.
I've seen all of this chaos play out all because Developer 1 forgot to reset the styles back to Overall, I think a generic reset/normalize stylesheet is better off pushing the burden on "islands of widgets" because a lot less can go wrong there. |
You're conveniently leaving out the case where <div class="widget">
<div class="nested-widget"></div>
</div> *, ::before, ::after {
box-sizing: border-box;
}
.widget, .widget *, .widget ::before, .widget ::after {
box-sizing: content-box;
}
.nested-widget {
box-sizing: border-box;
} That will break and will require the site author to pinpoint target their own dedicated CSS rules with higher specificity to fix it. This is the reason both implementations of 'border-box all the things' are flawed, btw. |
That problem is only difficult because you decided that this was a best practice. Maybe re-evaluate that. |
Oh yes; let's force site authors to needlessly write higher-specificity selectors to cater to the whims of forcing non-default behavior on box-sizing. And then let's cover up that mess by saying those site authors should re-evaluate their position on the practice of managing selector specificity to keep it low. Now there's a clear-cut case of "I reject your reality and substitute my own." |
With css variables you could have the advantages of both variants, but maybe that's too mutch overhead. html {
--box-sizing:border-box;
}
*, ::before, ::after {
box-sizing: var(--box-sizing);
}
.elementNeedsContentBox { /* but does not inherit */
box-sizing: content-box;
}
.widget {
--box-sizing: content-box; /* will inherited */
}
.nested-widget {
--box-sizing: border-box; /* will inherited */
} |
Counter to the common trend, it is not always 'awesome' or 'FTW'. It wreaks havoc with expectations stemming from normal browser defaults, which makes it harder to integrate into existing properties and makes it harder to integrate anything created by third parties that are not operating off of the same opinionated principle.
It's also a total pain in the ass to selectively undo with override rules, as it's reapplied on every element. At the very least you could use
box-sizing: inherit
I'd think, which makes it at least somewhat easier to selectively cut this awesomely annoying behavior out?The text was updated successfully, but these errors were encountered: