CSS box-sizing is the
box-sizing property that selects which box edge applicable length and percentage sizes refer to. With content-box, such sizes describe the CSS content box; with border-box, they include padding and borders in the CSS border box. Margins remain outside both.[ref]CSS Box Sizing Module Level 3 by World Wide Web Consortium. §3.3, Box Edges for Sizing: content-box and border-box
For example, use
width: 200px; padding: 16px; border: 2px solid, with no other constraints. Under content-box sizing, the content width is and the CSS border box width isCSS pixels. Changing only to box-sizing: border-box makes the CSS border box width and the content widthpixels. This is why a width declaration cannot be interpreted independently of its sizing edge.The content width cannot become negative. If the declared border-box width is only pixels but total horizontal padding and borders require , the content width floors at zero and the actual border box is pixels wide. Border-box sizing does not make arbitrarily thick padding disappear.[ref]
CSS Box Sizing Module Level 3 by World Wide Web Consortium. §3.3, zero floor on inner size and padding-plus-border overflow example
CSS box-sizing changes size interpretation rather than making every property apply to every box. A CSS non-replaced element generating an ordinary inline box still has its width applicability rules. CSS minimum size, CSS maximum size and the surrounding layout also remain relevant to the final CSS used value.
Articles by others on the same topic
There are currently no matching articles.