* { box-sizing: border-box } FTW
paulirish.com
paulirish.com
Even if the majority of people preferred the IE5.5 box model, it didn't follow the spec and it is therefore wrong. We have standards specifications on the web to maintain cross-browser compatibility; if browser vendors don't follow them then whats the point?
Specs should standardize what's generally considered a good idea. They are not written in stone and have no value in and on itself. If IE's old model was consensually better (and I'm not sure it was), the spec should have changed, not the other way around.
After all these years writing CSS, I'm very biased and it's hard to evaluate which is better. I was aware of border-box, but I thought it was Webkit only. Though I probably won't make the switch altogether, I'm glad to know we have a choice.
Glad to see others think this too, I always thought it was just me.
That actually seems the wrong way round to me. If you think about a document, the margin is what separates text from the edge of the page (or interior padding, if you will). Padding, to me, implies an area around an element that other elements can't touch.
Not really. Everybody I've known (in about a decade) has felt the IE box model made more sense.
But here's the thing: it wasn't the standard, the standard was not going to change its default box model, and dealing with a single slightly worse box model would always be better than dealing with two completely different box models.
box-sizing is the alternative, and a pretty good one. But I don't think anyone ever read about the differences between the W3C box model and the MSIE box model and thought "wow, the W3C box model makes so much more sense".
I don't wanna know how many hours I've spent calculating widths-after-padding(-but-wait-it's-different-on-both-sides) and commenting the CSS so other developers know why this element is width: 169px even though the container is 200px...
Not to mention:
textarea { width:100%; padding:20px; oh shit. }This may take some getting used to.
doodling
Also the konami code makes the same sort of unicorns appear that were on the video.
http://jsfiddle.net/gSD94/2/ http://jsfiddle.net/gSD94/2/embedded/result/
(great article too!)
edit: better link (fullscreen!)
And the equivalent code is available on Github: https://github.com/paulirish/harmony
Harmony procedural drawing tool, by mrdoob: http://mrdoob.com/projects/harmony/
dollar recognizer project (draw a star on paul's background!): http://depts.washington.edu/aimgroup/proj/dollar/
inspired by paul's site's implementation, about a year ago, i made a proof of concept captcha thing ("motioncaptcha"): http://www.josscrowcroft.com/demos/motioncaptcha/
Box analogy: when you add foam padding to a box to protect its content, are you effectively widening the box or reducing the volume it can fit?
Still, very cool trick, and the drawing is incredibly smooth.
Although, I don't find harmony.js a very nice way sorts.
Especially when dealing with fluid layouts, this guy is a lifesaver
Weird timing - after years of coding I literally found this box-sizing solution today on SO just a couple hours before seeing it here on HN.
The W3C box model is IMO one of the worst design flaws in front-end dev. It's a model that doesn't follow that of a real box! When you have padding (stuffed newspaper, peanuts, etc) in a packing box, the actual width and height of the box doesn't change! Border-width(or the thickness of the cardboard) is also included in the box dimensions.
I've only heard very weak reasons in the past for the W3C version and I'm surprised we haven't gotten past it. I think border-box will become more important as we head towards cross-platform responsively designed apps and sites with tons of layout decisions to consider. With simple sites up until now, you could afford the loss of control or the cognitive overhead to figure out workarounds. But now, I don't want to think the unintuitive way every time I'm making a layout decision for different screens.
http://personal.x-istence.com/post/2010/04/25/css-3-needs-be...
I was working on my portfolio site (link in my profile) and was frustrated with the CSS layout rules. It makes a lot more sense (at least to me) for the way it works with box-sizing: border-box than what it was previously.
If I were not afraid of having my portfolio site also easily accessible by HR in various different companies (many still with IE 6) I'd have used the experimental tags. Instead I used a work-around.
I'm eager to use it, but as I use Bootstrap I imagine it breaks it ?
- The search form was noticeably shorter and more cramped. I fixed this by adding height: 100% to the interior text input element
- Text inputs are less wide than they should be when you use bootstrap's span classes
- The navbar's vertical and horizontal dividers disappeared. I fixed this by adding 1px of padding to either the side or bottom of the divider, as the case required.
- Side tabs are a less wide than they should be
Might have been a glitch of some sort, but I'd suggest OP should check his source code to see if he hasn't been compromised of some sort.
<3
You'll know, so I am asking it here. Or is it even a right question in the first place?
I have learned a lot from your work on Boiler Plate, HTML5 and Modernizr. Let me dig deep into zooming and come up with its results.
(everying apart from <=ie7)
There are even lists compiling those bugs, such as http://www.positioniseverything.net/explorer.html
One of the biggest failings of the W3C model was that you could not combine a percentage width with fixed margin. If you wanted a fluid layout but which still incorporated consistent margins it was impossible to achieve without an entirely unnecessary nesting of divs.
Border-box completely eliminated this and poor old Microsoft (in this one instance) were forced to fall in with the less helpful "standard".
However, they did not, which means that in order to make a decent flowing layout, you have to change your document markup to insert artificial and otherwise unnecessary elements (DIV tags usually).
Thus the original model was flawed, did not make sense, and ultimately was not consistent with their own stated goals (separation of content and style).
[edit: FWIW petenixey said essentially the same thing, and what's really clever is that he said it first.]
Works in Firefox and IE. At some point WebKit will catch up, I assume.