boxSizing style property
8 | ||||
Specifies or retrieves how the width and the height of the element are calculated. It affects the height and width properties.
Note: The boxSizing property is supported in Internet Explorer from version 8.
Use the MozBoxSizing property in Firefox and the webkitBoxSizing property in Google Chrome and Safari instead.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: box-sizing |
Possible values:
The type of this property is string.
One of the following values:
The height and width properties include the padding and the border but not the margin. | |||||||
The height and width properties include only the content but not the margin, border and the padding. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
The height and width properties include everything (margin, border, padding, content). | |||||||
The height and width properties include the padding but not the margin and the border. |
Default: content-box.
Example HTML code 1:
This example illustrates the use of the box-sizing, -moz-box-sizing and the -webkit-box-sizing properties:
|
||||
<head> <style> .sizingContentBox { width: 200px; height: 70px; border: 5px solid #ffbc79; box-sizing: content-box; -moz-box-sizing: content-box; -webkit-box-sizing: content-box; } .sizingBorderBox { width: 200px; height: 70px; border: 5px solid #ffbc79; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } </style> </head> <body> <div class="sizingContentBox"> Width and height do not contain the padding, border and margin. </div> <br /> <div class="sizingBorderBox"> Width and height contain the padding and the border but not the margin. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the boxSizing, MozBoxSizing and webkitBoxSizing properties in JavaScript:
|
||||
<head> <style> .example { padding: 30px; border: 15px solid red; width: 250px; height: 50px; box-sizing: content-box; -moz-box-sizing: content-box; -webkit-box-sizing: content-box; } </style> <script type="text/javascript"> function ChangeBoxSizing (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var boxSizing = selectTag.options[whichSelected].text; var div = document.getElementById ("myDiv"); if ('boxSizing' in div.style) { div.style.boxSizing = boxSizing; } else if ('MozBoxSizing' in div.style) { div.style.MozBoxSizing = boxSizing; } else if ('webkitBoxSizing' in div.style) { div.style.webkitBoxSizing = boxSizing; } else { alert ("Your browser doesn't support this example!"); } } </script> </head> <body> <div class="example" id="myDiv"> Division with box-sizing: content-box </div> <select onchange="ChangeBoxSizing (this);" size="5"> <option selected="selected" />content-box <option />padding-box <option />border-box <option />margin-box <option />inherit </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, bdo, big, blink, blockquote, body, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plaintext, pre, q, rt, ruby, s, samp, small, span, strike, strong, sub, sup, table, td, textarea, th, tr, tt, u, ul, var, xmp
Related pages:
MozBoxSizing
webkitBoxSizing
MozBoxAlign
MozBoxDirection
MozBoxFlex
MozBoxOrdinalGroup
MozBoxOrient
MozBoxPack
webkitBoxSizing
MozBoxAlign
MozBoxDirection
MozBoxFlex
MozBoxOrdinalGroup
MozBoxOrient
MozBoxPack
External links:
box-sizing (MSDN)
-moz-box-sizing (Mozilla Developer Center)
-webkit-box-sizing (Safari Reference Library)
-moz-box-sizing (Mozilla Developer Center)
-webkit-box-sizing (Safari Reference Library)
User Contributed Comments