In the last few tutorials, we discussed two out of the three types of CSS rules. The first type is the HTML selector which is based on and controls the style for the matching HTML tag. The second type is the class selector which works like a generic style that can be applied to any element on the webpage. Now its time to discuss the third type of CSS rule which is called the ID selector. As with the class selector, the ID selector can be applied to any element on the webpage. However, it is meant to be used only once on a page. This makes the ID selector very useful for dynamic HTML and JavaScript. Theoretically, if you use the ID selector more than once on a page, the subsequent ones should be ignored by the web browser. However, this is not always the case. It is very difficult to rely on the predictability of web browsers. Therefore, when you choose to use the ID selector, be careful to use it only once. Let’s take a look at an example. Basic Code
Example
| |||||