4 ms·
> You see, a box (the rectangular space taken up by an element) has several measurements: its own width and height, then surrounding whitespace called padding,
by warning26 5y ago
> You see, a box (the rectangular space taken up by an element) has several measurements: its own width and height, then surrounding whitespace called padding, then an optional border, then a margin separating it from neighboring boxes. CSS specifies that these properties are all additive.
I never understood why CSS picked the obviously wrong way to define the box model. Who in their right mind would ever think that "width" would refer to the inner width of a box? I'm glad they finally added box-model: border-box, but the fact that there needed to be a switch at all is ridiculous.
- nauticacom 5y agoIt's pretty silly to claim that one way or the other is "obviously" wrong. A primary objective of defaults on the web is to never hide content; if "width" specifies the width of the content itself (i.e. box-sizing: content-box), when I say "div { width: 100px }" and put an image that's 100px in that div, I never crop/lose content. You can argue one way or the other, but neither is "obviously" more correct.