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

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

    There interesting situation when using box-sizing inside body content

    no content no border box gives no any value on left-right margin % recount of this two box recount algoritms

      .body{
        box-sizing: border-box;
        margin:0 3%;
      }
    

    Firefox versions before 57 also supported the padding-box value for box-sizing, though this value was been removed from the specification and later versions of the browser.

    So margin-box even not planned...

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-04 12:27

    I'm sure all of this is obvious, but I'll type it out anyway because...well, I need the exercise. Would the following outcome not be just as efficient as box-sizing: margin-box;:

    .col2 {
        width: 45%;
        height: 90%;
        margin: 5% 2.5%;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        float: left;
    }
    

    http://jsfiddle.net/Fg3hg/

    box-sizing is used to control from which point the padding and border are assessed to the overall size of the element. So while it's not kosher to include px margins with a % width (as is usually always the case), it's easier to calculate what the relative percentage amount should be because you don't have to incorporate padding and borders to the defined width.

    0 讨论(0)
提交回复
热议问题