Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

The Box Model 181

8


so, you can use the margin-left and margin-right properties or provide multiple values
for the margin property. So, to center a

horizontally, the following style sheet is
used. (The n ewly centered
is in Figure 8.10.)


Input ▼


.inner { border: 2px dotted black;
background-color: white;
padding: 15px;
width: 50%;
margin-left: auto;
margin-right: auto;
}


Output ▼


FIGURE 8.10
A centered <div>.

If you want elements to overlap each other, you can apply nega-
tive margins to them rather than positive margins.

TIP

I used the width property in that style sheet to shrink the

so that it could be cen-
tered. I explain how to resize elements using CSS later in the lesson.


Another thing to remember is that the of the page is a box, too. Here’s a style
sheet that includes new values for the border, margin, and padding properties of the


tag. It also includes some changes to the outer
to illustrate how the changes
to the tag work. You can se e the updated page in Figure 8.11.