basics of website design banner photo

HTML

HTML 5

CSS 2.1

CSS 3

Reference

Pseudo-elements

Pseudo-elements were introduced to allow designers to access and apply styles to locations in the document which cannot be selected using normal CSS selectors. Unlike other elements, pseudo-elements don't appear in the source code of a document or the document tree for a page.

There are four pseudo-elements in the CSS 2.1 specification:

Examples

:first-line

p.altered:first-line{color: red; font-size: 2em;}

This paragraph of text has been styled using the :first-line pseudo-element, the first line of text has the text colour changed to red and the size of the font has been doubled.

:first-letter

p.altered:first-letter{color: red; font-size: 2em;}

This paragraph of text has been styled using the :first-letter pseudo-element, the first letter of text has the text colour changed to red and the size of the font has been doubled.

The before and after pseudo-elements are used in conjunction with the CSS content property.

:before

p.altered:before{content: "Design tip: "; text-transform: uppercase;}

This paragraph of text has been styled using the :before pseudo-element and the content property to insert the text 'Design tip: ' before any paragraph of the specified class and change the text to uppercase.

:after

p.altered:after{content: "THE END. "; font-family: cursive;}

This paragraph of text has been styled using the :after pseudo-element and the content property to insert the text 'THE END.' after any paragraph of the specified class and change the font to cursive.