Web Design

(Nancy Kaufman) #1

134


Apply Styles with Classes .......................................


2 Within a tag to which you
want to apply the style, type
class=”?”, replacing?
with a class name.

1 In your editor, open a page
that contains an embedded
style sheet.

Apply Styles with Classes


W


hen you apply styles by using an element selector, the style affects every instance of that element
on the page. Often, you want to target the style only at a few instances of the element, which can

be done with a class selector and attribute. The class selector is used in your CSS to create a generic set


of rules, whereas the matching class attribute is added to your HTML to specify to which tag the class’


rules should be applied. In your CSS, the class name must begin with a period, but the period is not


used in the attribute in HTML.


2


1

Free download pdf