CSS-Lesson 3
Selectors
CSS selectors include all HTML tags, alone and in combinations. In addition there are author-generated elements and a small number of pseudo elements.
Selector | Use | Examples |
---|---|---|
universal | use to create a rule applicable to all tags | |
tag | apply the rule to all instances of the tag | h1 p |
multiple tag* | separate tags with a comma | h1,h2,h3 |
descendent selector | Apply to the second tag if it is nested somewhere within the first tag | p em p.center |
parent-child tag | Apply to the second tag if it nested immediately within the first tag | body > p |
id* | a single use on any one page | #name tag#name |
class* | use for multiple uses on a page | .name tag.name |
pseudo-element | e.g. for drop-caps or for putting the first line in small caps | p:first-letter p:first-line |
pseudo-class* | used for changing links according to their state | a:hover a:active a:focus a:link a:visited |
adjacent tags | apply to the second tag if it is next to the first tag | h1 + h2 p + h3 |
attribute selector | apply to tags that have the attribute shown in the square brackets | th [colspan] |
NOTE
* indicates the most commonly used form of selectors. Others are described in later lessons.
Inheritance
Some property values show an alternative 'inherit'. This implies that the property is not given because the selector inherits that property from a containing selector.
CSS comments
Comments in CSS are shown like this:
/*
CSS comment goes here.
*/