<body> The Document's BodyThe 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:
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:
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.
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. |