css - Is there a reason why padding adds to the size of an element? -


I was surprised when I found that and

gt; & Gt; - If you give it 10px padding then 200px becomes 220px wide. It does not make sense to me, the external setting should not be changed when the internal setting is

EDIT: I know how this happens, it's going to work, my question is this? Is it logical that I can not understand? Can it give any benefit to the opposite and the opposite approach to keeping the padding separate?

There are two separate ones - the unused "box model", a specified width , while not the second, with the arrival of CSS3, you can fortunately switch between the two models. More accurate, the behavior you want can be achieved by specifying

  box-sizing: border-box; MS-Box-Size: border-box; Webkit-box-size: border-box; Socks-box-size: border-box; Width: 200px; 

In your div's CSS again, in modern browsers, the div will always be 200 px wide, no matter what. For a list of more details and supported browsers, see.

Edit: Your edit as WRT is why is like a traditional box model, in fact Wikipedia:

Before HTML4 and CSS, very few HTML elements supported both border and padding, so the definition of the width and height of an element was not very controversial. However, it varies by element, the HTML width of the table defines the width of the table with its range, on the other hand, the HTML width attribute of an image has defined the width of the image (within any range). In those early days, the only element to support padding was the table cell that was defined as the width of the cell as "the suggested width for cell contents in pixels except for cell padding".

CSS has introduced margins, borders and padding for many more elements. It adopts the width of the definition in relation to the content, range, margin and padding for a table cell. Since then W3C is known as the box model.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -