body The Document s Body

<body> The Document's Body

The document's body is where the action isthe content that the document is designed to contain, that is. The <body> element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, and XHTML 1.1. Here are this element's attributes:

  • alink Deprecated in HTML 4.0 (you use styles instead now). Sets the color of hyperlinks when they're being activated. (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • background Deprecated in HTML 4.0. Holds the URI of an image to be used in tiling the browser's background. (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • bgcolor Deprecated in HTML 4.0 (you use styles instead now). Sets the color of the browser's background. (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.)

  • link Deprecated in HTML 4.0 (you use styles now). Sets the color of hyperlinks that have not yet been visited. (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 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • text Deprecated in HTML 4.0. Sets the color of the text in the document. (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

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

  • vlink Deprecated in HTML 4.0 (you use styles instead now). Sets the color of hyperlinks that have been visited already. (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 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

This element also supports these events in XHTML: onclick , ondblclick , onload , onmousedown , onmouseup , onmouseover , onmousemove , onmouseout , onkeypress , onkeydown , onkeyup , and onunload . You can use scripts such as JavaScript with events like these; I'll take a look at how in the next chapter.

If you place descriptions of your document in the <head> element, you place the actual content of the document in the <body> elementunless you're sectioning your page into frames , in which case you should use the <frameset> element instead of the <body> element.

We've already seen a simple example in which the content of a page is just an <h1> heading, like this:

 <?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>             Welcome to my page         </title>     </head>  <body>   <h1>   Welcome to XHTML!   </h1>   </body>  </html> 

If you've written HTML, you may be startled to discover that many cherished attributes are now considered deprecated in XHTML, which means they're omitted from XHTML 1.0 Strict and XHTML 1.1. Deprecated attributes of the <body> element include these:

  • alink

  • background

  • bgcolor

  • link

  • text

  • vlink

Instead of using these attributes, you're now supposed to use stylesheets. Here's an example showing how to replace deprecated attributes. In this case, I'll set the browser's background to white, the color of displayed text to black, the color of hyperlinks (created with the <a> element, which I'll take a look at in the next chapter) to red, the color of activated links to blue, and the color of visited links to green, all using deprecated attributes of the <body> element:

Listing ch16_04.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>             Welcome to my page         </title>     </head>  <body bgcolor="white" text="black" link="red" alink="blue"   vlink="green">  Welcome to my XHTML document.         Want to check out more about XHTML?         Go to         <a href="http://www.w3c.org">W3C</a>.     </body> </html> 

You can see this document displayed in Netscape Navigator in Figure 16-3. It works as it should, but it's not strict XHTML.

Figure 16-3. Displaying a hyperlink in Netscape Navigator.

graphics/16fig03.gif

To make the same page adhere to the XHTML strict standard, you use stylesheets. Here's how this page looks using a <style> element to set up the same colors (I'll take a look at the <style> element more closely in the next chapter):

Listing ch16_05.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>             Welcome to my page         </title>  <style type="text/css">   body {background: white; color: black}   a:link {color: red}   a:visited {color: green}   a:active {color: blue}   </style>  </head>     <body>         Welcome to my XHTML document.         Want to check out more about XHTML?         Go to         <a href="http://www.w3c.org">W3C</a>.     </body> </html> 

In this case, I'm using CSS to style this document. To separate content from markup, W3C is relying on stylesheets a great deal these days. However, note that the contents of a <style> element are still part of the XHTML document, which means that if you use sensitive characters such as & or < in it, you should either escape those characters or use an external stylesheet. I'll take a look at external stylesheets in the next chapter.



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