In CSS, the class selector is displayed with a dot: ##In the above example, all HTML elements with the center class are centered.
In the HTML code below, both h1 and p elements have the center class. This means that both will obey the rules in the ".center" selector.
.center {text-align: center}
Note: The first character of the class name cannot use numbers! It won't work in Mozilla or Firefox.
Like id, class can also be used as a derived selector:
<h1 class="center"> This heading will be center-aligned </h1> <p class="center"> This paragraph will also be center-aligned. </p>
Elements can also be selected based on their class:
.fancy td { color: #f60; background: #666; }
td.fancy { color: #f60; background: #666; }
The above is the detailed content of What does the CSS class selector look like (code). For more information, please follow other related articles on the PHP Chinese website!