Pseudo-classes, online

Six activities your students do on their own devices. See who's finished, and their scores.

Pseudo-classes in one minute

What students need to know

:last-child selects the final child element within its parent container. Pseudo-classes use a colon (:). A dot (.) selects a class attribute, not a state.

:hover responds to mouse position. :focus responds to keyboard or click focus. :first-child targets only the first child of a parent, not all matching elements.

Mistakes students make

  • Pseudo-classes use a colon, not a dot. a.hover tries to match an element with class='hover'. The correct selector is a:hover.
  • CSS declarations need a colon between the property and value. It should be border: 2px solid blue; not border 2px solid blue;.
  • The CSS property is color (American English), not colour. It should be color: white; not colour: white;.
  • CSS uses a colon between property and value, not an equals sign. It should be opacity: 0.8; not opacity = 0.8;.

Discover other journeys with this module

What students will learn in this module

Every question in Module 39

Quick questions

  1. Which syntax correctly applies a pseudo-class?Aa:hover { color: red; }Ba.hover { color: red; }
  2. :hover activates when...Athe mouse pointer is over the elementBthe element receives keyboard focus
  3. Which pseudo-class targets an element while it is being clicked?A:activeB:focus
  4. li:first-child selects...Aevery li element on the pageBthe first li inside its parent
  5. Pseudo-classes use a single colon or double colon?ADouble colon — e.g. ::hoverBSingle colon — e.g. :hover

Key terms

Students type the meaning of:

  • pseudo-class

Match the pairs

a:hoverMatch it to what it does
input:focusMatch it to what it does
Targets the last child element in a parentMatch it to what it does
Targets elements by their numeric position among siblingsMatch it to what it does
a.hover { color: red; }Match it to what it does
button::active { background: blue; }Match it to what it does

Fill in the blanks

  1. a:_____ {
      color: red;
    }

    Hint: Type the pseudo-class that activates when a mouse pointer moves over an element

  2. input:_____ {
      outline: 2px solid blue;
    }

    Hint: Type the pseudo-class that activates when an element receives keyboard or click focus

  3. li:___________ {
      font-weight: bold;
    }

    Hint: Type the pseudo-class that targets the first child element inside a parent

  4. li:__________ {
      color: gray;
    }

    Hint: Type the pseudo-class that targets the last child element inside a parent

  5. button:______ {
      background: green;
    }

    Hint: Type the pseudo-class that applies while a button is being clicked

Spot the error

Question 1

Aa.hover {B  color: orange;C}

Question 2

Ainput:focus {B  border 2px solid blue;C}

Question 3

Abutton:active {B  background: darkblue;C  colour: white;

Question 4

Aa:visited {B  text-decoration: none;C  color: purple;D  opacity = 0.8;

Question 5

Ali:first-child {B  font-size: 18px;C  font-weight: bold;D  color: navy;E  text-align centre;