CSS Cookbook, 2nd Edition

Problem

You want to center text within a paragraph or a heading.

Solution

Use the text-align property with the value set to center:

h3 { text-align: center; } p { text-align: center; }

Discussion

The center value for the text-align property is designed to control the alignment of inline content within a block element.

See Also

The CSS 2.1 specification for text-align property at http://www.w3.org/TR/CSS21/text.html#alignment-prop; for information about centering various items in a web page, see Recipe 4.3.

Категории