The boxSizing
property gets and sets
how to fit elements to an area.
boxSizing |
Yes | Yes | Yes (MozBoxSizing) | Yes | Yes |
Return the boxSizing property:
var v = object.style.boxSizing
Set the boxSizing property:
object.style.boxSizing='content-box|border-box|initial|inherit'
Default Value: | content-box |
---|---|
Return Value: | A tring representing the box-sizing property |
CSS Version | CSS3 |
The following code shows how to change the box-sizing property.
<!DOCTYPE html>
<html>
<head>
<style>
div.container {<!--from ww w. ja va 2 s. c om-->
width: 300px;
border: 1px solid;
}
div.box {
width: 150px;
border: 3px solid coral;
float: left;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="box" id="box1">This is BOX1.</div>
<div class="box" id="box2">This is BOX2.</div>
<div style="clear:both;"></div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("box1").style.MozBoxSizing = "border-box"; /* Code for Firefox */
document.getElementById("box2").style.MozBoxSizing = "border-box"; /* Code for Firefox */
document.getElementById("box1").style.boxSizing = "border-box";
document.getElementById("box2").style.boxSizing = "border-box";
}
</script>
</body>
</html>
The code above is rendered as follows: