*{ box-sizing: border-box }

扶醉桌前 提交于 2019-12-07 00:35:59

问题


*{
  box-sizing: border-box;
}

Is this a good idea? Any drawbacks?

I find this very useful when I want an element to have 100% and some inner padding. Because I don't have to add another element inside for the padding :/


回答1:


I have started to use this almost always.

The Pros,

You do not need to calculate out the CSS box-model anymore.

You can easily add large padding to an object without have to re-fix your height/width

Faster coding of your css (look up SASS if you have not)

The cons,

IE7 and below have no support, who cares right? Some sadly do.

IE8 and up have only partial support.

This is how I go about this if I don't want everything to have it,

div, li, p {
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
}

I add the elements that I know will utilize this property and to prevent every object from having that property.




回答2:


The biggest drawback is that it doesn't work in a lot of browsers, most specifically < IE8. Check it out the usage here.

When I use this, I usually make sure I have all of the following in my stylesheet

.my-element {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
}


来源:https://stackoverflow.com/questions/19940459/box-sizing-border-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!