font-family: Arial;
}
Selectors come in a variety of flavors. If you want all of your hyperlinks (the to display in italics, add the following to your stylesheet:
a element)
a element)
If you want to be more specific and only italicize the hyperlinks that are containedsomewhere within an
h1 tag, add the following to your stylesheet:
h1 a { font-style: italic; }
You can also define your own custom selectors by adding
your HTML tags. Consider the following HTML snippet:
id and/or class attributes to
<h1 class="loud">Hi there!</h1>
<p>Thanks for visiting my web page.</p>
<p>I hope you like it.</p>
<ul>
<li class="loud">Pizza</li>
<li>Beer</li>
<li>Dogs</li>
</ul>
If we add
.loud { font-style: italic; } to the CSS for this HTML, Hi there! and Pizza the a class of in this snippet (or in HTML at all, for that matter).Applying CSS by tag, use the following rule:will show up italicized because they both have the loud class. The dot in front of.loud selector is important—it’s how the CSS knows to look for HTML tags withloud. If you omit the dot, the CSS will look for a loud tag, which doesn’t existid is similar. To add a yellow background fill to the highlight paragraph
#highlight { background-color: yellow; }
Here, the
To recap, you can opt to select elements by tag name (e.g.,
(e.g.,
get more specific by chaining selectors together (e.g.,
# symbol tells the CSS to look for an HTML tag with the ID highlight.body, h1, p), by class name.loud, .subtle, .error), or by ID (e.g., #highlight, #login, #promo). And, you canh1 a, body ul .loud).
There are differences between you have more than one item on the page with the same
Conversely,
When I first learned this, I figured I’d just always use class attributes so I wouldn’t have to worry about whether I was duping an ID value.However, selecting elements by ID is much faster than by class, so you can hurt your performance by overusing class selectors.class and id. Use class attributes whenclass value.id values have to be unique to a page.
a { font-style: italic; }
0 comments:
Post a Comment