Skip to Content
Web Design in a Nutshell, 3rd Edition
book

Web Design in a Nutshell, 3rd Edition

by Jennifer Robbins
February 2006
Intermediate to advanced
826 pages
63h 42m
English
O'Reilly Media, Inc.
Content preview from Web Design in a Nutshell, 3rd Edition

Centering with borders and margins

The final three-column example improves on the previous absolute positioning example. First, padding, borders, and margins are added to the center column in a way that works for Internet Explorer 5 for Windows as well as current browsers. Then the entire layout is centered in the browser window using one of the techniques covered at the beginning of this chapter. The resulting layout is shown in Figure 24-7. Background colors have been added to the sidebar elements to reveal their size and position.

The source document hasn’t changed, but there are three basic changes to the style sheet as pointed out in the comments and discussed in more detail following the example.

Adding padding, borders, and margins

Figure 24-7. Adding padding, borders, and margins

    body {
        margin: 0px;
        padding: 0px;text-align: center; } /* to allow centering in IE */
     
    #container {
        position: relative;  /* makes "container" the containing block */
        margin: 0 auto;   /* the proper CSS way to center */
        width: 700px;
        text-align: left; /* overrides text-align rule on body */
    }
     
    #masthead {
        height: 70px;
        background: #CCC; }
     
    #main {
        position: absolute;
        top: 70px;
        left: 150px;
        width: 400px;
        border-left: solid 1px black;
        border-right: solid 1px black;
        margin: 0 10px;
        padding: 0 10px;
    /* This is the box-model hack for IE 5 */
        voice-family: "\"}\"";
        voice-family:inherit;
        width:358px; } /* provides the correct width value */  ...
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.
Start your free trial

You might also like

Beginning Responsive Web Design with HTML5 and CSS3

Beginning Responsive Web Design with HTML5 and CSS3

Jonathan Fielding

Publisher Resources

ISBN: 0596009879Errata Page