Chapter 7. Padding, Borders, Outlines, and Margins
In Chapter 6, we talked about the basics of element display. In this chapter, we’ll look at the CSS properties and values you can use to affect how element boxes are drawn and separated from one another. These include the padding, borders, and margins around an element, as well as any outlines that may be added.
Basic Element Boxes
As discussed in the preceding chapter, all document elements generate a rectangular box called the element box, which describes the amount of space that an element occupies in the layout of the document. Therefore, each box influences the position and size of other element boxes. For example, if the first element box in the document is an inch tall, the next box will begin at least an inch below the top of the document. If the first element box is changed and made to be 2 inches tall, every following element box will shift downward an inch, and the second element box will begin at least 2 inches below the top of the document.
By default, a visually rendered document is composed of numerous rectangular boxes that are distributed so that they don’t overlap. Boxes can overlap if they have been manually positioned or placed on a grid, and visual overlap can occur if negative margins are used on normal-flow elements.
To understand how margins, padding, and borders are handled, you must understand the box model, illustrated in Figure 7-1.
Figure 7-1. The CSS box model
The diagram in Figure 7-1 intentionally ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access