Exforsys

Home arrow Technical Training arrow CSS Tutorials

CSS Pseudo Classes

Author : Exforsys Inc.     Published on: 24th Mar 2006    |   Last Updated on: 17th Apr 2006

CSS Pseudo Classes

In this tutorial you will learn about Cascading Style Sheets (CSS) - Pseudo Classes, Link, First letter and First line

Ads

CSS has pre-defined pseudo classes.
pseudo class has special syntax, the rule starts with the selector, then the pseudo class, and finally the declaration, the selector and the pseudo class are separated with a colon “:”.

CSS defines the following pseudo classes:
link, hover, active visited, first-line, and first-letter.

Link

To define link properties, you can use four pseudo classes, they are:

• link: sets the style of the unvisited link.
• hover: sets the style of the link when mouse goes over it.
• active: sets the style of the link when activated.
• visited: sets the style of the visited link.

Example:

a:link
{
color: #0000FF;
}
a:visited
{
color: #FF0000;
}
a:hover
{
color: #00FF00;
}
a:active
{
color: #0000FF;
}

This sets the link color to be in blue when unvisited and when active, to be in red when visited, and to be in green when mouse goes over it.

First letter

To set a different style for the first letter of an element, use the pseudo class “first-letter”, this can set the first letter font, color, and text properties.

Example:

p
{
font-size: 10px;
}
p: first-letter
{
color: red;
}

This will display the first letter of the element < p > in red color.

First line

To set a different style for the first line of an element, use the pseudo class “first-line”, this can set the first line font, color, and text properties.

Ads

Example:

p
{
font-size: 10px;
}
p: first-line
{
color: red;
}

This will display the first line of the element < p > in red color.

Read Next: CSS Media Types


 
This tutorial is part of a CSS Tutorials tutorial series. Read it from the beginning and learn yourself.

CSS Tutorials

 

Comments