ptg16476052
Selectors 163
8
In this case, tags that appear within tags will be italicized. If a tag cite { color: green; } In this case, we have one rule that applies to all tags, and the two others that cite { color: green; } In this case, the nested styles override the default style for the tag because they tags, the contents will The ability to override property settings by using more specific selectors is what provides Sometimes selecting by tag (even using contextual selectors) isn’t specific enough for To apply a selector to a class, use a leading. in the class name in your style sheet. So, if then you write the rule like this .imprtnt { color: red; font-weight: bold; } Any element with the class imprtnt will appear in bold red text. If you want to give this div.imprtnt { color: red; font-weight: bold; }
appears inside a list item, the contents will be rendered in boldface. Let’s add in one
more rule:
p cite { font-style: italic; font-weight: normal; }
li cite { font-style: normal; font-weight: bold; }
you’ve already seen. In this case, the contents of all tags will be green, and the
appropriately nested tags will take on those styles, too. Here’s one final example:
p cite { font-style: italic; font-weight: normal; color: red; }
li cite { font-style: normal; font-weight: bold; color: blue; }
are a more specific style definition. The contents of tags that don’t meet the crite-
ria of the nested rules will appear in green. The nested rules will override the color speci-
fied in the less-specific rule, so for tags that are inside
be red. Inside list items, the contents will be blue.
the ability to set styles with the precision of the style attribute from a style sheet. This is
called CSS specificity.
Classes and IDs
your needs, and you must create your own classifications for use with CSS. There are
two attributes supported by all HTML tags : class and id. The class attribute is used to
classify elements, and the id attribute is for assigning identifiers to unique elements.
you have a tag like this
treatment to only important
class name in your rule.
p.imprtnt { color: blue; font-weight: bold; }