Css pseudo-class and pseudo-element

Pseudo-class and pseudo-element are properties you can use to add certain functionality/behavior to some selector. We have used one before (:hover) in the css preloading example. The syntax is quite simple and is the same for both element and class:

selector : pseudo-class{...}

selector : pseudo-element{...}

Pseudo-element:

  • :first-line, add style on the first line of text of the selector
  • :first-letter, add style to the first letter of the selector
  • :before, :after, can be used with ‘content’ to add some content before and after the selector. (not supported by IE)

Pseudo-classe:

  • :active, add style when the selector is in his active state.
  • :visited, add style to links when theyhave been visited.
  • :link, add style to uvisited link.
  • :hover, add style when the mouse roll-over it. (only for links in IE)
  • :focus, add style when the selector has the focus.
  • :first-child, add style to the first child of the selector.

Leave a reply