A detailed explanation of the Box Model in CSS and a detailed explanation of the CSS Box Model
Many people are confused about the box model. The following uses a simple code to analyze the structure of the box model!
For easy viewing! Draw a table in the first div and set its size to the same size as the div content! Set the margin and padding attributes of the body to 0px;
This example uses the CSS style in the row!
The Code is as follows:
| 12345678910111213141516171819202122 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><Title> Box Model </title> <body><div> <div> <table width="900px" height="100px" border="1" cellspacing="0" cellpadding="0" bordercolor="#FF0000"> <tr > <td> </tr> </table> </div> <div> <div> <div></div></body> |
Open the ruler!
What have you found?
The analysis is as follows:
Display Effect:
Other settings of the table are fixed, that is, the content size will not change, but the change is only the location!
Border: it is a border that expands outward and can be added to it.Color Attribute;
Margin: There is no color attribute for outward expansion, so we can see that the expanded color is an external color. In this example, It is colorless!
Padding: It is filled inwards and has no color attribute. The displayed color is the color set for the internal content!