You know the Box Model for CSS (margin-border-padding-content)
However, I want browser to calculate sizes of a box model including margin,border and padding.
Is there a way开发者_开发知识库 to force browser to interpret like this?
Thanks
In CSS3, we have box-sizing
. If you set it to border-box
, it will calculate padding and border into the size. AFAIK you can't make it calculate also the margin into the size, which sounds logical, because margin is by no means part of a box, it just tells how much space should be left empty around a box.
See here: http://www.css3.info/preview/box-sizing/
Please also check out the current browser support for box-sizing
(even though it seems to be quite wide, you should avoid surprises).
No. According to W3c, the standard way is that width/height is interpreted without border and padding. You can force IE to follow the standard by adding a doctype
.
That is the standard behavior, you should use that for crossbrowser bojects.
精彩评论