center Centering Displayed Text

<center> Centering Displayed Text

The <center> element is a very popular one that centers its enclosed text in the display area of the Web browser. Like many other styling elements and attributes in HTML 4.0, it was deprecated in favor of stylesheets, so it's supported only in XHTML 1.0 Transitional and XHTML 1.0 Frameset. Here are the attributes of this element:

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

  • 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 Transitional, XHTML 1.0 Frameset.)

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

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

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

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

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

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

The <center> element does just what its name implies: centers text and elements in the browser's display area. The W3C deprecated <center> in HTML 4, so you won't find it in the XHTML 1.0 Strict or XHTML 1.1 DTDs. Nonetheless, <center> remains a favorite element and will be in use for a long time to come.

Here's an example of <center> at work centering multiline text:

Listing ch16_13.html
 <?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;center&gt; Element         </title>     </head>     <body>         <center>             <h1>                 Using the &lt;center&gt; Element             </h1>         </center>         <center>             The &lt;center&gt; element is a             <br />             useful one for centering             <br />             text made up of             <br />             multiple lines.         </center>     </body> </html> 

You can see the results of this XHTML in Figure 16-11.

Figure 16-11. Using the <center> element.

graphics/16fig11.gif

The <center> element is still in widespread use, which is why I'm taking a look at it here. However, it has been deprecated, which means that it will disappear from XHTML one day. So what are you supposed to use instead? Take a look at the next topic, the <div> element.



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