English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The CSS box model describes how elements are visually laid out on a webpage.
Each element that can be displayed contains one or more rectangular boxes. The CSS box model typically describes how these rectangular boxes are arranged on a webpage. These boxes can have different properties and can interact with each other in different ways, but each box has a content area and optional surrounding margins, borders, and padding.
The following figure demonstrates how the margin, padding, and border CSS properties determine the space that an element can occupy on a webpage.
Generally, when you use CSS widthandheightWhen setting the width and height of an element, in fact, you are only setting the width and height of the element's content area. The actual width and height of the element box depend on several factors.
The actual space that the element box may occupy is calculated as follows:
Box Size | CSS Property |
---|---|
Total Width | width+ padding-left+ padding-right+ border-left+ border-right+ margin-left+margin-right |
Total Height | height+ padding-top+ padding-bottom+ border-top+ border-bottom + margin-top+margin-bottom |
The usage of different properties given in the following chapters.
Note:In the CSS box model, the content area of the element box is the area where text, images, lists, tables, forms, videos, and other elements are displayed.