p Organizing Text into Paragraphs

<p> Organizing Text into Paragraphs

The <p> element is a very popular one when dealing with text in Web pages; it allows you to break text up into paragraphs. Paragraphs are block elements that you can format as you like in stylesheets or with style attributes, including indenting the first line and so forth. If you're coming to XHTML from HTML, one issue to flag is that every <p> tag needs a corresponding </p> tag, which is easy to forget because HTML doesn't require that. In addition, note that paragraphs are block elements, which in XHTML means that you cannot display other block elements, such as headings, in them. The <p> element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, and XHTML 1.1. Here are this element's attributes:

  • align Deprecated in HTML 4 (you're supposed to use styles now instead). Sets the alignment of the text. Possible values include left (the default), right , center , and justify . (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • class Gives the style class of the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • dir Sets the direction of text that doesn't have an inherent direction in which you should read it, called directionally neutral text. You can set this attribute to LTR , for left-to-right text, or RTL , for right-to-left text. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • id Refers to the element; set this attribute to a unique identifier. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • lang Specifies the base language used in the element. Applies only when the document is interpreted as HTML. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • style Set to an inline style to specify how the browser should display the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • title Contains the title of the element (which might be displayed in ToolTips). (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • xml:lang Specifies the base language for the element when the document is interpreted as an XML document. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

This element supports these XHTML events: onclick , ondblclick , onmousedown , onmouseup , onmouseover , onmousemove , onmouseout , onkeypress , onkeydown , and onkeyup .

You use the <p> element to organize your text into paragraphs. Paragraphs are rudimentary formatting structures that separate text into easily handled block elements. The browser adds a little vertical space on top to separate them from other elements. The browser formats the text in a paragraph to fit the current page width.

Here's the XHTML example using the <p> tag we saw in the previous topic:

 <?xml version="1.0"?>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">     <head>         <title>             Using the &lt;br&gt; and &lt;p&gt; Elements         </title>     </head>     <body>         <center>             <h1>                 Using the &lt;br&gt; and &lt;p&gt; Elements             </h1>         </center>         This is a line of text.         <br />         Using a line break skips to the next line.  <p style="font-weight: bold">   This is a line of bold text in a paragraph.   <br />   Here's a new line of text in the same paragraph.   </p>  </body> </html> 

This example points out the difference between <br> and <p> . The <br> element is empty and just makes the flow of text skip to the next line. The <p> element, on the other hand, is a block element that encloses content. You can apply styles to the content in a <p> element, and those styles are applied to all text in the paragraph, even if broken up with line breaks. You can see this in Figure 16-9, where the bold style of text applies to both lines in the paragraph.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

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