The property names often heard in web design: content, padding, border, margin, the CSS box model has all these properties. We can understand these properties by using a common thing in daily life - a box as a metaphor, so it is called the box model. The CSS box model is a thinking model used by CSS technology that is often used in web design. Introduction CSS (Cascading Style Sheet) can be translated as "Cascading Style Sheet" or "Cascading Style Sheet". It defines how to display HTML elements and is used to control the appearance of Web pages. By using CSS to separate the content and presentation of the page, work efficiency is greatly improved. CSS assumes that all HTML document elements generate a rectangular element box that describes the space occupied by the element in the HTML document layout, which can be figuratively regarded as a box. CSS has created a concept of "box model" around these boxes. By defining a series of box-related properties, it can greatly enrich and promote the performance and layout structure of each box and even the entire HTML document. For box elements, if there is no special setting, they always occupy an independent line by default, and their width is the width of the browser window. The elements before and after them, whether they are boxes or not, can only be arranged above or below them, that is, they are arranged cumulatively up and down. Each box in an HTML document can be seen as consisting of four parts from the inside to the outside, namely the content area (content), padding (padding), border (border) and margin (margin). CSS defines a series of related properties for the four parts. By setting these properties, the performance of the box can be enriched. CSS Box Model In CSS, we can regard all HTML elements as a box. We can take div as an example. In the browser inspector, we can also observe the appearance of the box model more intuitively as shown in the figure: 1. The composition of the box model: Content area: content (the blue area in the middle of the picture) Note the difference between the size of the box and the size of the box in the browser 2. Classification of box models: 1) content-box: div{ width: 100px;//Width of the content area height: 100px;//Height of the content area border: 5px solid pink; padding:10px; margin: 10px; } The width of the box: width + border-left + border-right + padding-left + padding-right 2) border-box: width:200px; //Width of the box height:200px; //Height of the box Height of the content area: height - border-top - border-bottom - padding-top - padding-bottom 3. Use of the box model Summarize This is the end of this article about the CSS box model that you should not be confused about. For more relevant CSS box model content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Mac+IDEA+Tomcat configuration steps
>>: How to prevent event bubbling in JavaScript
I used vue and bootstrap to make a relatively sim...
Today a client wants to run an advertisement, and ...
Table of contents Preface Method 1: High contrast...
1. WebDesignerWall 2. Veerle's Blog 3. Tutori...
This article shares the specific code of WeChat a...
one. First of all, you have to package it in idea...
introduce If you are using an OSS storage service...
I recently read about vue. I found a single-file ...
Table of contents Constructing payment methods us...
How to modify the mysql table partitioning progra...
MySQL query by year, month, week, day group 1. Qu...
Table of contents design Component Communication ...
Preface: When we are making web pages, we often n...
1. Business scenario introduction Suppose there i...
In Linux systems, especially server systems, it i...