10. CSS Class Selector

A class selector is the XHTML element with a matching class attribute that is to be given style or layout properties. A class selector is defined in CSS by using the "." sign followed by the value of the class attribute (no space between the “.” and the name of the class). A class attribute value is not required to be unique; the same class name within an XHTML document may be used multiple times.

Example 10 Class Selector Usage
<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Element selector</title>
    <style type="text/css">
    .test {
        Property:Value;
    }
    </style>
</head>
<body>
    <div class="test">Styled by a class selector.</div>
    <div class="test">Styled by a class selector.</div>
</body>
</html>
    

In the above example the elements with a class attribue value of test will be given style or layout properties.