Graphical CSS padding, margin, border properties
The organization recommends that all the images on the Web page be placed in a box where the designer can control the properties of the box by creating a definition that includes paragraphs, lists, headings, pictures, and layers. The box model mainly defines four regions: content, padding (padding), Border (border), and margin (margin). For beginners, it is often unclear the level, relationship and interaction between margin,background-color,background-image,padding,content,border. Here is a box model of 3D, hoping to facilitate your understanding and memory.
Margin: white space left outside the bounding box of the layer background-color: Background color background-image: Background picture padding: a blank between the layer's border and the content of the layer border: border Content: Contents
The next step is to tell the box model, the key to HTML and CSS. The key to understanding the box model is the margin and padding attributes, and the correct understanding of the two properties is the key to learning CSS layouts.
Note: Why not translate margin and padding?
Reason one: there is no corresponding word in Chinese;
Reason two: Even if there is such a word, because in the writing of CSS code, must use margin and padding, if we always use Chinese words instead of its interpretation, to the practical application of the concept of easy to confuse the margin and padding.
If you have a bit of HTML, you should know some basic elements (element), such as P, H1~h6, BR, p, LI, UL, IMG, etc. If these elements are broken down, they can be top-level (top-level), block-level (block-level), and inline (inline) elements, respectively.
Block-level elements are the primary and key elements that make up an HTML, and any block-level element can be interpreted with the box model.
Box Model: Any block-level element consists of content, padding, background (including background color and picture), border (border), margin five parts.
The stereoscopic chart is as follows:
The floor plan is as follows:
According to the above two figures, I believe you will have an intuitive understanding of box model.
The margin and padding properties are described below:
1, margin: including Margin-top, Margin-right, Margin-bottom, Margin-left, control the distance between block-level elements , they are transparent invisible. According to the upper, right, lower and left clockwise rules, can be written as margin:40px 40px 40px 40px;
For easy memory, please refer to:
When the upper and lower margin values are consistent, they can be abbreviated as:
margin:40px 40px;
The previous 40px represents the up and down margin value, and the next 40px represents the left and right margin values.
When the upper and lower margin values are consistent, can be abbreviated as:
margin:40px;
2, Padding: including Padding-top, Padding-right, Padding-bottom, Padding-left, control block-level elements within the distance between content and border, its code, For shorthand, refer to the notation for the margin attribute.
At this point, we have a basic understanding of the basic usage of the margin and padding properties. However, in practical applications, there are always some things that make you elusive, and they are more or less related to margin.
Note: When you want the content of two elements to be separated vertically (vertically), you can select either Padding-top/bottom or Margin-top/bottom, and then ruthless It is recommended that you try to use Padding-top/bottom to achieve your goal, because there are collapsing margins (collapsed margins) in the CSS.
Collapsing Margins:margins folding phenomenon exists only in the adjacent or subordinate element, in the vertically oriented margin.
Detailed description is as follows:
If only one is provided, it will be used for all four edges;
If two are supplied, the first one is used up-down and the second one is for left-right;
If three are supplied, the first one is used on, the second one is for left-right, and the third one is used for the next;
If you provide all four parameter values, the upper-right-bottom-left order is used for four-sided.
body {padding:36px;}//The patch margin on the four sides of the object is 36px body {padding:36px 24px;}//patch margin is 36px up and down, the patch margin between right and left is 24px body {padding:36px 24PX 18px; }//upper and lower sides of the patch margins are 36px, 18px, the left and right side of the patch margin of 24px body {padding:36px 24px 18px 12px;}//Up, down, down, left patch margins are 36px, 24px, 18px, 12px, respectively
Graphical CSS padding, margin, border properties
The organization recommends that all the images on the Web page be placed in a box where the designer can control the properties of the box by creating a definition that includes paragraphs, lists, headings, pictures, and layers. The box model mainly defines four regions: content, padding (padding), Border (border), and margin (margin). For beginners, it is often unclear the level, relationship and interaction between margin,background-color,background-image,padding,content,border. Here is a box model of 3D, hoping to facilitate your understanding and memory.
Margin: white space left outside the bounding box of the layer background-color: Background color background-image: Background picture padding: a blank between the layer's border and the content of the layer border: border Content: Contents
The next step is to tell the box model, the key to HTML and CSS. The key to understanding the box model is the margin and padding attributes, and the correct understanding of the two properties is the key to learning CSS layouts.
Note: Why not translate margin and padding?
Reason one: there is no corresponding word in Chinese;
Reason two: Even if there is such a word, because in the writing of CSS code, must use margin and padding, if we always use Chinese words instead of its interpretation, to the practical application of the concept of easy to confuse the margin and padding.
If you have a bit of HTML, you should know some basic elements (element), such as P, H1~h6, BR, p, LI, UL, IMG, etc. If these elements are broken down, they can be top-level (top-level), block-level (block-level), and inline (inline) elements, respectively.
Block-level elements are the primary and key elements that make up an HTML, and any block-level element can be interpreted with the box model.
Box Model: Any block-level element consists of content, padding, background (including background color and picture), border (border), margin five parts.
The stereoscopic chart is as follows:
The floor plan is as follows:
According to the above two figures, I believe you will have an intuitive understanding of box model.
The margin and padding properties are described below:
1, margin: including Margin-top, Margin-right, Margin-bottom, Margin-left, control the distance between block-level elements , they are transparent invisible. According to the upper, right, lower and left clockwise rules, can be written as margin:40px 40px 40px 40px;
For easy memory, please refer to:
When the upper and lower margin values are consistent, they can be abbreviated as:
margin:40px 40px;
The previous 40px represents the up and down margin value, and the next 40px represents the left and right margin values.
When the upper and lower margin values are consistent, can be abbreviated as:
margin:40px;
2, Padding: including Padding-top, Padding-right, Padding-bottom, Padding-left, control block-level elements within the distance between content and border, its code, For shorthand, refer to the notation for the margin attribute.
At this point, we have a basic understanding of the basic usage of the margin and padding properties. However, in practical applications, there are always some things that make you elusive, and they are more or less related to margin.
Note: When you want the content of two elements to be separated vertically (vertically), you can select either Padding-top/bottom or Margin-top/bottom, and then ruthless It is recommended that you try to use Padding-top/bottom to achieve your goal, because there are collapsing margins (collapsed margins) in the CSS.
Collapsing Margins:margins folding phenomenon exists only in the adjacent or subordinate element, in the vertically oriented margin.
Detailed description is as follows:
If only one is provided, it will be used for all four edges;
If two are supplied, the first one is used up-down and the second one is for left-right;
If three are supplied, the first one is used on, the second one is for left-right, and the third one is used for the next;
If you provide all four parameter values, the upper-right-bottom-left order is used for four-sided.
body {padding:36px;}//The patch margins on all sides of the object are 36px body {padding:36px 24px;}//Top and bottom patch margins of 36 PX, the left and right side of the patch margin of 24px body {padding:36px 24px 18px;}//upper and lower sides of the patch margins are 36px, 18px, the left and right sides of the patch margin is 24px body {padding:36px 24px 18px 12px; }//Top, right, bottom, left patch margins are 36px, 24px, 18px, 12px
, respectively