The best way I have seen so far of getting box-sizing working is: html { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } *, *::before, *::after { -webkit-box-sizing: inherit; -moz-box-sizing: inherit; box-sizing: inherit; } If your CSS reset (normalize.css) is inserted at the very top of your stylesheet
That page has statements like "content-box gives you the default CSS box-sizing behavior." and "content-box This is the initial and default value as specified by the CSS standard.", which seem to contradict with your "It explicitly mentioned in MDN that border-box is the default for box-sizing in the docs". –
By default it takes the value content-box. When box-sizing: border box, property-value combination is used in an element, this tells the browser to render the width property as the actual rendered
The CSS box alignment module specifies CSS features that relate to the alignment of boxes in the various CSS box layout models: block layout, table layout, flex layout, and grid layout. The module aims to create a consistent method of alignment across all of CSS. This document details the general concepts found in the specification.
Note that we have set the box-sizing property to border-box. This makes sure that the padding and eventually borders are included in the total width and height of the elements. Read more about the box-sizing property in our CSS Box Sizing chapter.
t4k39w. The inner size can’t be less than zero, so if the padding + border is greater than the specified border-box size, the box will end up larger than specified. In this case, the content-box size will floor at 0px so the border-box size ends up at 120px, even though width: 100px is specified for the border box:
W3C liability, trademark and permissive document license rules apply. This module extends the CSS sizing properties with keywords that represent content-based "intrinsic" sizes and context-based "extrinsic" sizes, allowing CSS to more easily describe boxes that fit their content or fit into a particular layout context.
O box model padrão do CSS é uma das coisas mais contra-intuitivas que existem. Mas você pode trocá-lo com o box-sizing do CSS3. E, melhor, funciona em todos os navegadores -- até no IE8! Todo elemento no HTML é uma caixa. Controlamos seu tamanho com width, sua borda com border e ainda temos as margens externas e internas com margin e padding.
content-box is the default, and gives you the default CSS box-sizing behavior. If you set an element's width to 100 pixels, then the element's content box will be 100 pixels wide, and the width of any border or padding will be added to the final rendered width.
Thuộc tính Box-sizing có hai giá trị phổ biến là content-box và border-box. Giá trị content-box: Khi sử dụng giá trị content-box, kích thước của một phần tử được tính toán chỉ dựa trên phần nội dung (content) bên trong phần tử.
box sizing border box vs content box