Example 9: centering blocks
This is the h1

The h1 block is centered in the the body by setting the left and right margins to "auto". The h1 text is not centered in the block.

The h1 width is a percentage, not pixels. Percentages often adjust better when the window or text is resized.

The paragraphs are centered as long as the window is wider than their width. They have a width in pixels, which will not change when the window is resized.

Centering text
this is the h2

The h2 text is centered within the block using the text-align property, but the block itself is not centered in the body.

The paragraphs also have the text centered within the block.

The style rules

        h1 {width: 50%;
            background: yellow; 
            margin-left: auto;
            margin-right: auto;}

        h2 {background-color: #ccffff;
            text-align: center;
            width: 75%}

        p {width: 620px;
           background: silver;
           margin-left: auto;
           margin-right: auto;
           text-align: center;}