8.3. ID Selector

The ID selector is used in conjunction with the id attribute of XHTML MP elements. The usage of the ID selector is similar to that of the class selector. First you associate some WCSS styles to a certain ID in a cascading style sheet. Then you specify the ID to the id attribute of the XHTML MP element you wish to apply the WCSS styles to.

A typical ID selector begins with the # character and is followed by the ID of an element. Here is an example:

#id_of_an_element {
  color: blue

The style rule "color: blue" will be applied to the XHTML MP element of which the id attribute is assigned with the value "id_of_an_element".

An ID selector can only be used to apply WCSS styles to one XHTML MP element, since no two XHTML MP elements can have the same id attribute value in a document. You have to use the class selector if the same WCSS styles have to be applied to multiple XHTML MP elements.

The following XHTML MP/WCSS example demonstrates how to apply WCSS styles using the ID selector in cascading style sheets.


<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <style type="text/css">
      #id_header {
        color: blue
    <title>WCSS Tutorial</title>

    <h1 id="id_header">Table of Contents</h1>
      WCSS Tutorial Chapter 1<br/>
      WCSS Tutorial Chapter 2<br/>
      WCSS Tutorial Chapter 3<br/>

In the above XHTML MP/WCSS example, the style rule "color: blue" is applied only to the level-1 heading tag. This is what you will see in some mobile phone emulators:

Sony Ericsson T610

Nokia Mobile Browser 4.0

If you specify an XHTML MP element name before the # character of an ID selector, the WAP CSS style rules can only be applied to that XHTML MP element. For example, suppose you define a WAP CSS statement like this:

h1#id_header {color: blue}

The above WAP CSS style rule can only be applied to <h1> elements. There will be no effect if it is applied to other XHTML MP elements. For example, the following markup code will cause the text "Table to Contents" to be displayed in blue in mobile phone browsers:

<h1 id="id_header">Table of Contents</h1>

However, if "id_header" is the id of a <p> element, the text of the paragraph will not be displayed in blue but will remain in its default color in a mobile phone browser.

<p id="id_header">
  WCSS Tutorial Chapter 1<br/>
  WCSS Tutorial Chapter 2<br/>
  WCSS Tutorial Chapter 3<br/>

Previous Page Page 9 of 39 Next Page

Feedback Form (ExpandCollapse)

What do you think about this web page?

(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page