Class Selectors


Class selectors can be used to select any HTML element that has been given a class attribute.

In the HTML sample shown in Listing 3.1, there are two HTML elements with class attributes<p > and <a href="#" >.

For example, to select all instances of the intro class, the .intro selector is used as shown in Listing 3.3.

Listing 3.3. CSS Code Containing Styling for the .intro Class
.intro {      font-weight: bold; } 

You also can select specific instances of a class by combining type and class selectors. For example, you might want to select the <p > and the <a href="#" > separately. This is achieved using p.intro and a.intro as shown in Listing 3.4.

Listing 3.4. CSS Code Containing Two Different Stylings of the .intro Class
p.intro {     color: red; } a.intro {     color: green; } 




Sams Teach Yourself CSS in 10 Minutes
Sams Teach Yourself CSS in 10 Minutes
ISBN: 0672327457
EAN: 2147483647
Year: 2005
Pages: 234
Authors: Russ Weakley

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