Backgrounds, online

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

Backgrounds in one minute

What students need to know

The rgba function sets Red, Green, Blue, and an Alpha transparency layer between 0 and 1. background-position: center automatically aligns the graphic vertically and horizontally.

The background shorthand combines color, image, position, size, and repeat into a single line. CSS uses the url() function to point to image sources for backgrounds.

Mistakes students make

  • Line 1 is incorrect because background-image values must be wrapped inside a url() function, not as a raw string.
  • Line 2 is incorrect because repeat-yes is invalid. Use repeat, no-repeat, repeat-x, or repeat-y.
  • Line 0 has invalid syntax; remove the colon following the class name '.main'.
  • Line 1 is incorrect. cover-all is invalid; use cover to scale the image proportionally.

Discover other journeys with this module

What students will learn in this module

Every question in Module 58

Quick questions

  1. Which property is a shorthand that can set color, image, and repeat values all at once?AbackgroundBbackground-style
  2. How should a background image file path be specified inside CSS?Asrc('image.jpg')Burl('image.jpg')
  3. Which value ensures a background image stretches proportionally to completely fill its container?AcoverBcontain
  4. Does a background-color render underneath or on top of a background-image?AOn top of the imageBUnderneath the image
  5. What is the default behavior of a background image if it is smaller than its container element?AIt repeats to tile the containerBIt stretches automatically

Key terms

Students type the meaning of:

  • background

Match the pairs

.box {
  background-repeat: no-repeat;
}
Match it to what it does
.banner {
  background-size: contain;
}
Match it to what it does
Sets a background color using a semi-transparent alpha channel value.Match it to what it does
Positions a background image to sit exactly in the middle of its bounding layout block.Match it to what it does
.alert {
  background-image: 'bg.png';
}
Match it to what it does
.hero {
  background-size: cover-all;
}
Match it to what it does

Fill in the blanks

  1. .box {
      ________________: red;
    }

    Hint: Type the property used to change the background color

  2. .card {
      ________________: url('img.png');
    }

    Hint: Type the property used to add a background image

  3. .hero {
      background-repeat: _________;
    }

    Hint: Type the value that prevents background images from repeating

  4. .header {
      background-size: _____;
    }

    Hint: Type the value that stretches a background image to fully cover the element

  5. .main {
      ___________________: center;
    }

    Hint: Type the property used to align the background image position

Spot the error

Question 1

A.banner {B  background-image: 'bg.jpg';C  background-color: blue;D}

Question 2

A.section {B  background-color: #fff;C  background-repeat: repeat-yes;D}

Question 3

A.main: {B  background: url('pattern.png') repeat-x;C  padding: 20px;D}

Question 4

A.header {B  background-size: cover-all;C  background-position: center;D}

Question 5

A.card {B  background-color: transparent;C  background-positioning: top left;D}