205-03

Link pseudo-classes

Slide instructions

SPACEBAR to move forward through slides.

SHIFT & SPACEBAR to move backwards through slides.

LEFT ARROW & RIGHT ARROW to move through sections.

ESC to see overview and ESC again to exit.

F to enter presentation mode and ESC to exit.

Introduction

Pseudo-classes (or “fake” classes) allow you to style specific attributes or states that do not exist in the document tree.

:link pseudo-class (CSS1)

The :link pseudo-class selector is written using an element, followed by ":", followed by "link".


/* syntax */
E:link { }

/* example */
a:link { }

Whitespace is not permitted within the selector.


/* Valid */
a:link { }

/* Invalid */
a :link { }

How does it work?

The :link pseudo-class selector targets any link that is defined as “unvisited”.

Specifications

W3C Selectors Level 4
Status: Working Draft

Selectors Level 3
Status: Recommendation

CSS Level 2 (Revision 1)
Status: Recommendation

Support

The :link pseudo-class selector is well supported across all modern browsers.

Exercise 1: Write a :link selector

Open this HTML file in an editor:
exercises-start/exercise-205-03-01.html

Write a CSS rule to style the <a> element to be color: lightsalmon.


/* Add styles here */
a:link {
  color: lightsalmon;
}

Check your work against the finished HTML file:
exercises-finished/exercise-205-03-01.html

:visited pseudo-class (CSS1)

The :visited pseudo-class selector is written using an element, followed by ":", followed by "visited".


/* syntax */
E:visited { }

/* example */
a:visited { }

Whitespace is not permitted within the selector.


/* Valid */
a:visited { }

/* Invalid */
a :visited { }

How does it work?

The :visited pseudo-class selector targets any link that is defined as “visited”.

Due to potential security issues, there are only a few properties that you can use to style visited links.

These include color, background-color, border-color, outline-color, fill, and stroke.

You can read more about potential security issues: Article 1, Article 2, Article 3.

Specifications

W3C Selectors Level 4
Status: Working Draft

Selectors Level 3
Status: Recommendation

CSS Level 2 (Revision 1)
Status: Recommendation

Support

The :visited pseudo-class selector is well supported across all modern browsers.

Exercise 2: Write a :visted selectors

Open this HTML file in an editor:
exercises-start/exercise-205-03-02.html

Write a CSS rule to style the <a> element to be color: mediumvioletred, but only when it is the visited state.


/* Add styles here */
a:visited {
  color: mediumvioletred;
}

Check your work against the finished HTML file:
exercises-finished/exercise-205-03-01.html

Russ Weakley

Site Twitter Github Slideshare Linkedin

Next deck

205-04: User-action pseudo-classes