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

后端 未结 9 1483
心在旅途
心在旅途 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:23

    On Codrops there are a couple of good articles on the subject of the effect of margins and row's forced to overflow. They suggest using the rem or em unit with a normalizer css setting font size to 100% for all browsers, then when you set widths and margins it is easy to keep track of the effect on the row's width by simply making a note in comments for the total width. A conversion of 16px to 1 em is the way to calculte the targeted viewports total witdh.

    Working like that for the dev stage at least and then if you want 'responsive' templates you can convert widths to % including the margin widths.

    The other and often simpler way they suggest to handle gutters is to use the pseudo after and the content: ''; on each of your columns which I find works really well. If you set a div class that is the defined last column such as end you can then target that class not to have the pseudo after, or to have a wider one; which ever best suits your layout.

    The added bonus of using this pseudo element method is it also gives you a target for shadows that can give a more 3d effect and greater depth to the flat image on the readers monitor as well. I am experimenting with this effect at the moment by scaling up the effects being used on buttons, 'tweaking' the gradients, and the z-index.

提交回复
热议问题