CSS Box Model
CSS Box Model
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout.
Is essentially a box that wraps around every HTML element. It consists of: margins (clears an area outside the border, the margin is transparent), borders (a border that goes around the padding and content), padding (clears an area around the content, the padding is transparent), and the actual content (the content of the box, where text and images appear).
Width and Height of an Element
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
//The total width of an element should be calculated like this:
// 320px (width)
// + 20px (left + right padding)
// + 10px (left + right border)
// + 0px (left + right margin)
// = 350px
// Total element height = height + top padding + bottom padding + top border
//+ bottom border + top margin + bottom margin
When you set the width and height properties of an element with CSS, you just set the width and height of the content area. To calculate the full size of an element, you must also add padding, borders and margins.