How to force browser to add padding, etc. to size?
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.
链接地址: http://www.djcxy.com/p/75592.html上一篇: 填充增加了一个盒子元素的总大小
下一篇: 如何强制浏览器添加填充等大小?