An element with box-sizing: content-box. With box-sizing: content-box, an element's size is calculated by adding the border, padding, and margin sizes to its width and height. Let’s say an 1. In most cases border-box makes more sense. I have never seen cases when content-box was a preferred, it makes styling more confusing and usually makes box grow beyond sizes you expect. – dfsq. Sep 10, 2017 at 9:55. There are elements where the default sizing is border-box though, so you have a good reason to reset it, no matter what to.
You just add padding, and it seems to make the boxes bigger; weird. So we're going to add Box Sizing and Border Box, and magically we've got Padding, but they didn't get bigger. No more minusing the padding from the size and width of the boxes. It's magic, let's work out how to do it now in VS code.
但也不能盲目地用,因为它会影响content,如果padding和border太大,会把内容挤掉的。 总结: box-sizing:content-box;在宽度和高度之外绘制元素的内边距和边框。 box-sizing:border-box;通过从已设定的宽度和高度分别减去边框和内边距才能得到内容的宽度和高度.
Setting a div elements box-sizing to content-box: .div {. box-sizing: content-box; } Examples 1 and 2 can be illustrated as follows: This output image has two div containers with a width of 300px, a border of 1px, and a padding of 20px. Inside each container is a div with a width of 100%. The first container div is set to border-box.
Box Sizing. Resources. The CSS box model is a very important concept to grasp. The box model is a way to describe the layout of an element and its content. The most important CSS properties we will go over are padding, border, and margin. Here is a nice diagram of the CSS box model: Diagram of the CSS Box Model. h4QGW. 821 415 564 804 624 239 460 340

box sizing border box vs content box