The Wayback Machine - https://web.archive.org/web/20071009063519/http://www.webreference.com:80/html/tutorial5/6.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

ID & CLASS selectors, Pseudoclasses

Developer News
IBM Unleashes Rational, Tivoli Tools For SMBs
Bungie Jumps Microsoft's Ship
Fuzzing at 18: Still Crude, Still Effective

CSS Selector syntax is actually very complex. There are very powerful ways of assigning styles to specific elements. In the long run, you will probably find yourself not using the STYLE attribute at all; it will be a lot easier to pinpoint a specific element instance using a selector and assigning a specific style to it.

This is accomplished using two new attributes that apply to all elements in HTML. These attributes are ID and CLASS.

Both ID and CLASS accept values called name tokens, a term borrowed from SGML. Name tokens may contain only English characters, digits, the dash (-) and period (.) characters.

If you assign an element an ID attribute, you single it out in a document; you have effectively given it a name. This is why it is not allowed to have more than one ID attribute in your document with the same value. Since the value of the ID attribute uniquely identifies an element, it would be wrong to give more than one element the same ID.

Here is an example (I will list only the document body for the sake of brevity):

<BODY>

<H1 ID="first">Acme Computer Corp.</H1>

<P>Acme Computer Corporation is a
technology-based company that seeks to offer 
its customers the latest in technological 
innovation. Our products are created
using the latest breakthroughs in computers 
and are designed by a team of top-notch 
experts.</P>

<H1 ID="second">Global Presence, Global 
Thinking</H1>

<P>We are based in Acmetown, USA, and have
offices in most major cities around the world. 
Our goal is to have a global approach to the 
future of computing. Have a look at our product 
catalog for some examples of our innovative
approach.</P>

<HR>

<ADDRESS>
Comments to: 
<A HREF="mailto:webmaster@acme.com">Web Master</A>, 
Acme Computer Corp., One Acme Road, AcmeTown, USA.
</ADDRESS>

</BODY>
</HTML>

Here, the first H1 element has an ID of "first", and the second H1 element has an ID of "second." These are simply names we have chosen for them; the words themselves have no special significance. Now, however, we can use a special selector syntax to refer to these elements specifically, like this:

H1#first { ...declarations... }
H1#second { ...declarations... }

The selectors mean, respectively, "the H1 element that has an ID of 'first'" and "the H1 element that has an ID of 'second'." We can also write them like this:

#first { ...declarations... }
#second { ...declarations... }

These selectors mean "the element that has an ID of 'first'" and "the element that has an ID of 'second'". This is effectively the same as before, as there can only be one element in the whole document that has the ID value of "first" or "second."

The ID attribute gives us a way of singling out elements in our document and giving them specific rendering styles. But what happens when we want to group two or more elements and assign the same style to them? Enter the CLASS attribute.

Front Page12345678910

Access FREE Tools and Resources from the HP ITIL Solution Center:
Morty Proxy This is a proxified and sanitized view of the page, visit original site.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.
ITIL v3 Webcast: Service Ops Are Key for Great Management
Start transforming your IT organization into a strategic business partner! Learn how.
ITSM Guide: Benefits to the ITIL Approach to Service Mgmt.
Get an ITIL overview & learn how organizations are applying it.
Whitepaper: Measuring the ROI of Mission Critical Services
Learn about availability services as an enabler of change and IT operational efficiency.
Whitepaper: 5 Essential Questions for choosing an ITIL Service Provider
Seeking an ITIL service provider? Read this first.

http://www.internet.com

Produced by Stephanos Piperoglou

Solutions


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2007 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
XML-Enabled Applications - Part 4 · Software Review: Synergy · XML-Enabled Applications - Part 3
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
String Functions: The .Properties Function, Part II · A NEXIS of NAS · 3Com Expands IP Communications Portfolio


All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial5/6.html
Created: August 20, 1998
Revised: August 20, 1998

Morty Proxy This is a proxified and sanitized view of the page, visit original site.