CodeBlanks Logo Icon CodeBlanks

Challenge - Box model

CSS course · Beginner · Lesson 79/82

Complete a card component using the box model.

Recall the box model

Every HTML element is a box. width and height set the content area, padding the inner space, border the edge, and margin the outer space. border-radius rounds the corners; box-shadow adds a shadow.

With box-sizing: border-box, padding and border are counted inside the width. The card width stays fixed and content no longer overflows. That is why most card components start with border-box.

Exercise Complete the card component

Add a .card class selector. Set width to 320px, padding to 1.5rem, and margin to 1rem. Set border-radius to 12px, box-shadow to 0 4px 12px rgba(0, 0, 0, 0.1), and box-sizing to border-box.

Show example solution
/* card component */
.card {
  width: 320px;
  padding: 1.5rem;
  margin: 1rem;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
}

Shadow and corner tips

box-shadow takes horizontal, vertical, blur and spread values: 0 4px 12px rgba(0, 0, 0, 0.1) gives a soft bottom shadow. A high blur softens the shadow; the last rgba channel tunes the strength.

With border-radius, small values round a card gently; large values give a button or badge look. Using both together makes cards feel deep and modern.

Test yourself

  1. What does box-sizing: border-box change?

    .card {
      width: 300px;
      padding: 1rem;
      border: 2px solid #333;
      box-sizing: border-box;
    }
    • Width grows beyond 300px
    • padding and border are counted inside 300px
    • margin resets to zero
    • border becomes invisible
    Show answer

    padding and border are counted inside 300px — Correct. With border-box, padding and border are counted inside width; the card stays 300px.

  2. Complete the value that rounds the card corners

    .card {
      padding: 1.5rem;
      border-radius: ____;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    Show answer
    .card {
      padding: 1.5rem;
      border-radius: 12px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
  3. Match each box property to its role

    width
    Content area width
    padding
    Inner space
    border
    Edge
    margin
    Outer space

All lessons in Beginner