CSSボックスサイズ設定プロパティ
例
要素の幅と高さの合計にパディングと境界線を含めます。
#example1 {
box-sizing: border-box;
}
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
このbox-sizing
プロパティは、要素の幅と高さの計算方法を定義します。パディングと境界線を含めるかどうかを指定します。
デフォルト値: | コンテンツボックス |
---|---|
遺伝性の: | いいえ |
アニメート可能: | 番号。アニメート可能について読む |
バージョン: | CSS3 |
JavaScript構文: | オブジェクト.style.boxSizing = "border-box" |
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
数字の後に-webkit-または-moz-が続く場合は、プレフィックスを使用して機能した最初のバージョンを指定します。
Property | |||||
---|---|---|---|---|---|
box-sizing | 10.0 4.0 -webkit- |
8.0 | 29.0 2.0 -moz- |
5.1 3.2 -webkit- |
9.5 |
CSS構文
box-sizing: content-box|border-box|initial|inherit;
プロパティ値
Value | Description |
---|---|
content-box | Default. The width and height properties (and min/max properties) includes only the content. Border and padding are not included |
border-box | The width and height properties (and min/max properties) includes content, padding and border |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
その他の例
例
2つの境界ボックスを並べて指定します。
div
{
box-sizing: border-box;
width: 50%;
border: 5px solid red;
float: left;
}
例
「ユニバーサルボックスサイジング」を設定します。
* {
box-sizing: border-box;
}
関連ページ
CSSチュートリアル:CSSボックスのサイズ設定
HTML DOMリファレンス:boxSizingプロパティ