Change the boxSizing property:
document.getElementById("myDIV").style.boxSizing = "border-box";
Try it Yourself »
The boxSizing property allows you to define certain elements to fit an area in a certain way.
For example, if you want two bordered boxes side by side, it can be achieved through setting boxSizing to "border-box". This forces the browser to render the box with the specified width and height, and place the border and padding inside the box.
Property | |||||
---|---|---|---|---|---|
boxSizing | Yes | Yes | Yes | Yes | Yes |
Return the boxSizing property:
object.style.boxSizing
Set the boxSizing property:
object.style.boxSizing = "content-box|border-box|initial|inherit"
Value | Description |
---|---|
content-box | Default value. This is the behavior of width and height as specified by CSS2.1. The specified width and height (and min/max properties) apply to the width and height respectively of the content box of the element. The padding and border of the element are laid out and drawn outside the specified width and height |
border-box | The specified width and height (and min/max properties) on this element determine the border box of the element. That is, any padding or border specified on the element is laid out and drawn inside this specified width and height. The content width and height are calculated by subtracting the border and padding widths of the respective sides from the specified 'width' and 'height' properties |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | content-box |
---|---|
Return Value: | A String, representing the box-sizing property of an element |
CSS Version | CSS3 |
CSS reference: box-sizing property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!