The box model
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Every box has layers
- CSS treats every element as a box.
- Content is your text or image. Padding is space inside, around the content.
- Border is a line around the padding. Margin is space outside, pushing other boxes away.
日本語
各ボックスにはレイヤーがある
- CSS はすべての要素をボックスとして扱います。
- コンテンツはテキストまたは画像です。パディングは、コンテンツの周囲にある内部のスペースです。
- ボーダーはパディングの周囲にある線です。マージンは外側のスペースで、他のボックスを押し広げます。
English
Padding and border
padding: 20px;adds 20 pixels of space inside, on all four sides.border: 2px solid black;draws a line — its width, style, then colour.- Padding makes a box feel roomy; a border makes it stand out.
日本語
パディングとボーダー
padding: 20px;がすべての4辺に内部に20ピクセルのスペースを追加します。border: 2px solid black;は線を描画します — その幅、スタイル、そして色。- パディングはボックスにゆとりを与え、ボーダーは目立たせます。
<style>
.card {
background-color: #eef;
padding: 16px;
border: 2px solid #88a;
}
</style>
<div class="card">A comfy padded card.</div>
English
Common mistakes
- The box model is content, then padding, then border, then margin (inside to outside).
- Padding adds space inside the border.
日本語
よくあるミス
- ボックスモデルは、コンテンツ、次にパディング、次にボーダー、最後にマージン(内側から外側へ)です。
- パディングはボーダーの内部にスペースを追加します。
English
Now you try
- Padding is inside; the border sits around it.
- Add padding to a box, then a border.
日本語
あなたも試してみよう
- パディングは内側にあります;ボーダーはその周りに位置します。
- ボックスにパディングを追加し、次にボーダーを追加します。
Explore · 探索
The CSS box model
Every box is content + padding + border + margin around it.
Give the box some breathing room inside. Add padding: 20px; to the .box rule.
Draw a line around the box. Add border: 2px solid navy; to the .box rule — keep the three parts in that order: width, style, colour.