Consider a version without forcing box-sizing
See original GitHub issueCounter 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?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Inheriting box-sizing Probably Slightly Better Best-Practice
But there is a little adjustment to setting it that seems like a pretty good idea. Here's the adjusted version: html { box-sizing:...
Read more >* { box-sizing: border-box } FTW - Paul Irish
The project has been tested in IE8 & 9 and the latests Firefox and Chrome versions and we've had no problems.
Read more >CSS3 box-sizing: margin-box; Why not? - Stack Overflow
I think we could have a box-sizing: margin-box . The css box model shows exactly, what are the positions of the margins of...
Read more >CSS Box Sizing Module Level 3 - W3C
This version: https://www.w3.org/TR/2021/WD-css-sizing-3-20211217/ ... a measure of text (without consideration of line-wrapping), ...
Read more >box-sizing - CSS: Cascading Style Sheets - MDN Web Docs
The box-sizing CSS property sets how the total width and height of an element is calculated. ... Samsung InternetNo. Toggle history.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
With css variables you could have the advantages of both variants, but maybe that’s too mutch overhead.
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:
Trees of components:
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
box-sizing: inherit
to every element is that it creates a simpler mental model when marking an entire sub-tree asbox-sizing: content-box
.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:
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
border-box
for<component-one/>
's children. I’ve also seen it play out that Developer 1 reset the styles incorrectly and broke theinherit
behavior for everyone.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.