Basic Selectors
- universal
- the * represents any tag, id or class, use this sparingly for definitions:
* { font-style: italic }
- tag
- tag selectors represent any single tag such as
div or p: p { line-height: 150% }
- id
- id represents a unique identifier in the document:
h3#headline { font-style: italic }
- class
- classes can be used on any number of elements, on any type of element:
li.menuitem { font-weight: bold }
tree selectors
- descendent( )
- this applies to a selector that is anywhere in the tree beneath the parent
- child(>)
- this selects only a selector immediately below the parent
- adjacent(+)
- this selects any item on the same level as the sibling
- attribute[attr]
- this selects any item with the specified attribute
pseudo-tags
- :focus
- (only valid on form elements and links) applies style to element when user is focused here
- :hover
- applies to any element that the mouse is over
- :active
- applies to links that are actively being clicked
- :visited
- applies to followed links
- :link
- applies to links that have never been followed
non-interactive psuedo-classes
- :first-child
- The :first-child pseudo-class matches an element that is the first child of some other element.
- :first-line
- The :first-line pseudo-element applies special styles to the first formatted line of a paragraph.
- :first-letter
- The :first-letter pseudo-element may be used for "initial caps" and "drop caps"
- :before, :after
- The ':before' and ':after' pseudo-elements can be used to insert generated content before or after an element's content.
cascade
- default
- These are the default values as defined by the browser
- user
- These are the values the user can set on his/her client to override the browser defaults
- author
- These are set by the page author and override both user and default values
!important
- user
- If a user adds
!important to his/her stylesheet, it will override the author's settings,
regardless of whether the author set !important
- others
- In any other location, a rule with
!important will override any other rule of the same attribute