Module 2 · CSS foundations16 min lesson

Style a card without guessing

Use CSS selectors and the box model to style a predictable learning card, then return to your saved practice after sign-in.

Start with the idea

01

A selector is a precise instruction.

CSS starts by choosing which elements receive a rule. A class selector begins with a dot, so .learning-card targets every element carrying class="learning-card".

.learning-card {
  color: #17231e;
  background: #ffffff;
}
.learning-card<article class="learning-card">

02

Combine selectors to keep a rule local.

A space means “inside.” The selector .learning-card strong reaches <strong> elements inside the card without changing every strong element on the page.

.learning-card strong {
  color: #175437;
}
Read selectors from right to left

Find a <strong> element, then check whether it sits inside .learning-card. This habit makes longer selectors easier to reason about.

03

The box model explains the space you see.

Every element has content, padding, border, and margin. Padding creates space inside the edge. Margin separates the whole box from its neighbours.

margin
border
padding
content · 280px card

By default, a declared width covers only the content. Add box-sizing: border-box when the padding and border should stay inside that width.

Five-minute practice

Make the card predictable before making it pretty.

Complete the saved CSS block below. The checks look for two scoped selectors and the box-model choices that keep the card at 280px.

Saved practice · CSS box model

Make one card hold its shape.

Finish the two selectors, keep padding inside the declared width, and give the card a visible edge. The preview updates as you type.

Expected outcomeOne 280px learning card that passes all four selector and box-model checks.
Not saved2/4practice checks
card.cssLocal draft
Live previewNetwork blocked

Practice checks

Four choices, checked on the server.

2/4 passing
Target the card with its class

Keep the card declarations inside a .learning-card selector.

Target only the count inside the card

Use .learning-card strong so the emphasis stays scoped to this component.

Keep padding inside the declared width

Add box-sizing: border-box to .learning-card.

Give the content room inside a visible edge

Add padding and a non-zero border to .learning-card so the box is easy to read.

Starter CSS is ready. Save when the card feels predictable.

More repetition, same model

Use six short challenges to make the pattern stick.

Practice selectors, spacing, box sizing, and reusable link targets with exact feedback after every attempt.

Open CSS practice

Active recall

Check your mental model.

75% to complete

Answer from memory. You can choose all four answers before deciding whether to check them.

01Which selector targets every element with class="learning-card"?
02What does .learning-card strong select?
03With box-sizing: border-box, what does width: 280px include?
04Which property creates space between a card’s content and border?

Choose answers from memory, then check your work.