HTML/CSS Service

CSS ID Selector

Category: CSS    |    1,467 views   |   

Description

An ID selector matches an element that has a specific id attribute value. Since idattributes must have unique values, an ID selector can never match more than one element in a document.

In its simplest form, an ID selector looks like this:

#navigation {
  ? declarations
}

This selector matches any element whose id attribute value is equal to"navigation". In this selector, which is equivalent to *#navigation, the universal selector is implied. The universal selector is often omitted in cases like this.

Of course, it’s possible to use a type selector with an ID selector, but it’s rarely necessary, since an ID uniquely identifies an element. Here’s an example that only matches an unordered list element with an id attribute value that’s equal to"navigation":

ul#navigation {
  ? declarations
}

Whitespace characters shouldn’t appear between the type selector and the ID selector.

Example

This example selector matches any element whose id attribute value is equal to"breadcrumbs":

#breadcrumbs {
  ? declarations
}
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • digg
  • del.icio.us
  • Stumble it
  • Furl
  • Reddit
  • BlinkList
  • Simpy
  • YahooMyWeb
  • Spurl

Share/Save/Bookmark

1 Star2 Stars

Tags:

0 responses so far!

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word