0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CSS box-sizingプロパティ:要素サイズの計算基準の定義

0
Last updated at Posted at 2026-08-13

😄この投稿は、codingeverybody.jpのコンテンツをもとに作成しています。

定義と使い方

box-sizingプロパティは、要素のサイズ(Size)を計算する際に基準となる領域(Area)を定義します。
要素のサイズ(Size)を計算する際の基準となる領域(Area)には、2つの種類があります。

  • content-box : コンテンツ領域(Content Area)のみをサイズ(Size)の計算に含めます。
  • border-box : コンテンツ(Content)、パディング(Padding)、境界線(Border)領域まですべて含めてサイズを計算します。

content-boxとborder-boxのサイズ計算基準の違いを図で確認してみましょう。
図の各色の領域はコンテンツ(Content)、パディング(Padding)、境界線(Border)を表しています。

box-sizing.jpg

形式の構文

selector {
    box-sizing: content-box | border-box;
}

構文

/* キーワード値(Keyword values) */
box-sizing: content-box;
box-sizing: border-box;

/* グローバル値(Global values) */
box-sizing: inherit;
box-sizing: initial;
box-sizing: revert;
box-sizing: revert-layer;
box-sizing: unset;

値

# content-box

content-boxは、要素の width と height をコンテンツ領域のみを考慮してサイズを計算します。
padding と border はサイズに含まれません。つまり、padding と border は要素のサイズの計算外として追加されます。
もし要素に padding や border がある場合、実際の要素のサイズよりも大きく見えます。
widthやheightを許容するすべての要素の中で、要素を除けばブラウザでデフォルトとして設定される初期値です。

# border-box

border-boxは、要素の width と height をコンテンツ領域、padding と border をすべて含めて計算します。
もし要素に padding や border があったとしても、実際の要素のサイズと同一です。

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?