Naming Elements


You can give your (X)HTML elements either a unique name or one that identifies them as belonging to a particular class. You can then apply styles to all elements with a given name.

To name unique elements:

Within the opening tag of the element, type , where name uniquely identifies the element.

To name groups of elements:

Within the opening tag of the element, type , where name is the identifying name of the class.

Figure 3.14. Add an id attribute to a unique element in order to identify it for later formatting or links. Add a class attribute to a group of elements to be able to format them all in one fell swoop.


Figure 3.15. The id and class attributes do not by themselves modify an element's appearance. They must be combined with CSS formatting to show their full strength (as described in Chapters 10 and 11).


Tips

  • Each id in an (X)HTML document must be unique. In other words, no two elements can be named with the same id.

  • More than one element may belong to, and thus be marked with, the same class.

  • For information about applying styles to an element with a particular id or class, consult Selecting Elements by ID or Class on page 140.

  • The class and id attributes may be added to most (X)HTML elements but are particularly useful with the div and span elements (see pages 6465).

  • The id attribute automatically turns the element into an anchor, to which you can direct a link. For more details, consult Creating Anchors on page 106.

  • Finally, the id attribute can also be used to identify elements that will be affected by a scripting language, such as JavaScript.





HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

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