Using Margins
Margins are commonly styled to control the space between elements. You'll have noticed that there's always a certain amount of space, by default, around content displayed in web browsers (visible in Figure 11-1). This can be controlled by changing the margin values in the body element (see Example 11-1).
Example 11-1. Setting margin values for the body element
[View full width]
NOTEYou'll see that I have no length value such as px or em after my 0. That's because a 0 value requires no length; the meaning is implicit.By setting the top and left margins to 0 in the body, the entire body element shifts, along with its children elements (see Figure 11-3).
body {font: 14px Verdana, Arial, Helvetica, sans-serif; color: white; background-color:black; margin-top: 0; margin-left: 0; border: 2px solid white;}
h1 {font-size: 24px; color: orange;}
h2 {font: italic 20px Georgia, Times, serif; color: #999; text-indent: 15px;}
Figure 11-3. Zeroing the body margins to the top and leftnotice the white border surrounding the body element and how it's flush to the top and left of the viewport.
[View full size image]

Example 11-2. Setting a range of margins and values to demonstrate their use
[View full width]
Figure 11-4 shows how the margins are applied. I've slipped some borders in there to help visualize the margins. You'll learn more about borders later this chapter.
body {font: 14px Verdana, Arial, Helvetica, sans-serif; color: white; background-color:black; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; border: 2px solid
white;}
h1 {font-size: 24px; color: orange; margin-top: 0; margin-right: 100px; border: 2px solidgreen;}
h2 {font: italic 20px Georgia, Times, serif; color: #999; text-indent: 15px;}
p {margin-left: 100px; margin-top: 5px; margin-bottom: 0; border: 2px solid yellow;}
Figure 11-4. Applying margins to a range of elements including the body, h1, and paragraph elements.
[View full size image]
