| The Element | | Print | |
The <body> element appears after the <head> element and contains the part of the Web page that you
actually see in the main browser window, which is sometimes referred to as body content. It may contain
anything from a couple of paragraphs under a heading to more complicated layouts containing forms
and tables, and is likely to constitute the majority of any XHTML document. Most of what you will be
learning in this and the following five chapters will be written between the opening <body> tag and
closing </body> tag.
The <body> element may carry all of the attributes from the attribute groups you are about to meet in the
next section. If you are using Transitional XHTML or HTML 4.1, you can use any of the following
deprecated attributes on the <body> element (which are covered in Chapter 8):
background bgcolor alink link vlink text
There are also several browser specific attributes that you might see used on the <body> element; these
also are covered in Chapter 8:
language, topmargin, bottommargin, leftmargin, rightmargin, scroll,
bgproperties, marginheight, marginwidth
Attribute Groups
As you saw in Chapter 1, attributes live on the opening tag of an element and provide extra information
about the element that carries them. All attributes consist of a name and a value; the name reflects a
property of the element the attribute is describing and the value is a value for that property. For example,
the xml:lang attribute describes the language used within that element; a value such as EN-US would
indicate that the language used inside the element is U.S. English. Many of the elements in XHTML can
carry some or all of the attributes you will meet in this section.
There are three groups of attributes that many of the XHTML elements can carry (as you have already
seen, the <html>, <head>, <title>, and <body> elements share some of these attributes). Because
these attributes are common to so many of the elements, they are grouped together here to avoid having
to repeat them each time they come up, so remember where you read this and you can keep referring
back to them. The groups are:
❑ Core attributes: The class, id, and title attributes.
❑ Internationalization attributes: The dir, lang, and xml:lang attributes.
❑ UI events: Attributes associated with events onclick, ondoubleclick, onmousedown,
onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, and
onkeyup (these are covered in more detail in Chapter 14).
Together the core attributes and the internationalization attributes are known as the
universal attributes.
Core Attributes
The four core attributes that can be used on the majority of XHTML elements (although not all) are:
id title class style
Where these attributes occasionally have special meaning for an element that differs from the description
given here they will be visited again; otherwise their use can generally be described as you see in the
subsections that follow.
The id Attribute
The id attribute can be used to uniquely identify any element within a page or style sheet. There are two
primary reasons that you might want to use an id attribute on an element:
❑ If an element carries an id attribute as a unique identifier it is possible to identify just that
element and its content (perhaps you want to link to a specific point in a document, to select one
specific element’s content, to associate a CSS style with a particular element, or identify that
element using a script).
❑ If you have two elements of the same name within a Web page or style sheet, you can use the id
attribute to distinguish between elements that have the same name (this is very likely, when you
think most pages will contain at least two or more paragraphs of text).
The syntax for the id attribute is as follows (where string is your chosen value for the attribute):
id="string"
For example, the id attribute could be used to distinguish between two paragraph elements, like so:
<p id="accounts">This paragraph explains the role of the accounts
department.</p>
<p id="sales">This paragraph explains the role of the sales
department.</p>
Note that there are some special rules for the value of the id attribute; it must:
❑ Begin with a letter (A–Z or a–z) and can then be followed by any number of letters, digits (0–9),
hyphens, underscores, colons, and periods (you may not start the value with a digit, hyphen,
underscore, colon, or period).
❑ Remain unique within that document; no two attributes may have the same value within that
XHTML document.
Before the id attribute was introduced, the name attribute served a similar purpose in HTML documents,
but its use was deprecated in HTML 4.01, and now you should generally use the id attribute in XHTML
documents. If you need to use the name attribute it is available in Transitional XHTML, but not Strict
XHTML.
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment.
| Users' Comments (0) |
|
No comment posted






