Recipe 2.17. Setting the Indent in the First Line of a Paragraph


Problem

You want to place an indent in the first line of each paragraph, turning the paragraphs in Figure 2-26 into the paragraphs in Figure 2-27.

Figure 2-26. The default rendering of the paragraphs


Figure 2-27. The paragraphs with first lines indented


Solution

Use the text-indent property to create the indent:

p {  text-indent: 2.5em;  margin: 0 0 0.5em 0;  padding: 0; }

Discussion

The text-indent property can take absolute and relative length units as well as percentages. If you use percentages, the percentage refers to the element's width and not the total width of the page. In other words, if the indent is set to 35% of a paragraph that is set to a width of 200 pixels, the width of the indent is 70 pixels.

See Also

The CSS 2.1 specification for more on the text-indent property at http://www.w3.org/TR/CSS21/text.html#propdef-text-indent.




CSS Cookbook
CSS Cookbook, 2nd Edition
ISBN: 0596527411
EAN: 2147483647
Year: 2006
Pages: 235

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net