• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Managing Style Sheets > 11.11. Creating Center-Aligned Body Elements

Creating Center-Aligned Body Elements

NN 4, IE 4

Problem

You want paragraphs or other body content of a fixed width to be center-aligned within the page.

Solution

You have two approaches available to you. One is backward-compatible, while the other works in standards-compatibility mode for the newer browsers (see Recipe 11.13). The backward-compatible approach is to encase the element to be centered within an arbitrary div element, and then assign the text-align style sheet rule to the outermost block-level element. For example, to center a group of narrow paragraphs on a page, begin with the following style sheet rule for the paragraphs:

p.narrow {width:70%}

Then wrap those paragraphs with a div element whose style sheet rule reads:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint