CSS3 box-sizing: margin-box; Why not?

后端 未结 9 1504
心在旅途
心在旅途 2020-12-04 11:39

Why don\'t we have box-sizing: margin-box;? Usually when we put box-sizing: border-box; in our style sheets we really mean the former.


9条回答
  •  一个人的身影
    2020-12-04 12:11

    Dimensions of block-level, non-replaced elements in normal flow must satisfy

    margin-left + border-left-width + padding-left + width + padding-right + border-right-width + margin-right = width of containing block

    When over-constrained, browsers must adjust either the left or right margin. I think that means the width of the margin box must equal the width of the containing block (i.e. 100%).

    For your case, transparent borders with box-sizing: border-box can work much like margins.

提交回复
热议问题