Then we’re subtracting the padding as well to round the corners of the content-box. See the Pen by thebabydino (@thebabydino) on CodePen. So let’s code this! We set a transparent border and a padding. We make sure they get subtracted from the dimensions we’ve set by switching to box-sizing: border-box. According to w3c specs for Box Model. The rendered width of a box type element is equal to the sum of its width, left/right border and left/right padding. So that means the values of padding and border-width affects the total width of the element. border-box makes it so that the outside of the border is considered the outside bounds of the element. thats why in the 200px example, the borders and padding take up the "inner" space. The easiest way to fix this is to adjust your box-sizing. The value you would use is box-sizing: border-box. This includes the padding and border in your box elements. You can read more about box-sizing here. A problem with this solution is that it only works on IE8+. no content no border box gives no any value on left-right margin % recount of this two box recount algoritms .body{ box-sizing: border-box; margin:0 3%; } Firefox versions before 57 also supported the padding-box value for box-sizing, though this value was been removed from the specification and later versions of the browser. Giải pháp hiện tại. Box model được nâng cấp (rất lâu rồi) với thuộc tính box-sizing, 2 value chính là: content-box và border-box. content-box: tất cả element đều được gán mặc định là content-box, và cũng là những gì mình phân tích ở trên. Hiện nay Box model đã được nâng cấp thành thuộc tính box-sizing với 2 value chính là content-box và border-box. Content-box: tất cả các element đều được gán ở chế độ mặc định là content-box. Khi thực hiện các thuộc tính width và height sẽ chỉ định nghĩa chiều rộng và cao của Box sizing adalah properti yang menerima nilai padding dan border pada suatu elemen termasuk sebagai nilai total dari width dan height suatu elemen. box-sizing: content-box (default)| border-box For more straightforward sizing in CSS, we switch the global box-sizing value from content-box to border-box. This ensures padding does not affect the final computed width of an element, but it can cause problems with some third party software like Google Maps and Google Custom Search Engine. q5Tf2.

box sizing border box vs content box