Stage 2: Frontend Fundamentals

CSS · Lesson 05

Flexbox

One-dimensional layout with justify-content, align-items, wrapping and gaps.

CSS3 min readFree lesson

Flexbox is a CSS technique for easily building one-dimensional layouts (a single direction, horizontal or vertical). It is used in most UI layouts, such as navigation bars, card lists, and centered content.


1. Flexbox Basics

.container {
  display: flex; /* Child elements become flex items */
}
  • Flex Container: The parent element with display: flex applied
  • Flex Item: The direct children of the Flex Container
[Container]
  ┌─────────────────────────────────────────┐
  │  [Item 1]  [Item 2]  [Item 3]          │
  └─────────────────────────────────────────┘
        → Main Axis (default: horizontal)

2. Direction (flex-direction)

.container {
  flex-direction: row;            /* Default: horizontal (left → right) */
  flex-direction: row-reverse;    /* Horizontal, reversed (right → left) */
  flex-direction: column;         /* Vertical (top → bottom) */
  flex-direction: column-reverse; /* Vertical, reversed (bottom → top) */
}

3. Main-Axis Alignment (justify-content)

Aligns items along the main axis.

.container {
  justify-content: flex-start;    /* Default: align to the start */
  justify-content: flex-end;      /* Align to the end */
  justify-content: center;        /* Center alignment */
  justify-content: space-between; /* First and last pinned, the rest spaced evenly */
  justify-content: space-around;  /* Equal space on both sides of each item */
  justify-content: space-evenly;  /* All gaps identical */
}

4. Cross-Axis Alignment (align-items)

Aligns items along the cross axis.

.container {
  align-items: stretch;     /* Default: fill the cross axis */
  align-items: flex-start;  /* Align to the start */
  align-items: flex-end;    /* Align to the end */
  align-items: center;      /* Center alignment (often used for vertical centering) */
  align-items: baseline;    /* Align by text baseline */
}

5. Wrapping (flex-wrap)

.container {
  flex-wrap: nowrap;   /* Default: no wrapping (items may overflow) */
  flex-wrap: wrap;     /* Move to the next line when overflowing */
  flex-wrap: wrap-reverse; /* New lines are added above */
}

6. Spacing (gap)

.container {
  gap: 16px;          /* Same gap for rows and columns */
  gap: 20px 10px;     /* Row gap 20px, column gap 10px */
  row-gap: 20px;      /* Row gap only */
  column-gap: 10px;   /* Column gap only */
}

7. Flex Item Properties

flex-grow / flex-shrink / flex-basis

.item {
  flex-grow: 1;    /* Share of the remaining space to take (default: 0) */
  flex-shrink: 1;  /* Rate of shrinking when space is tight (default: 1) */
  flex-basis: auto; /* Base size (default: auto) */

  /* Shorthand property */
  flex: 1;         /* flex-grow: 1, flex-shrink: 1, flex-basis: 0 */
  flex: 0 0 200px; /* Fixed size 200px (neither grows nor shrinks) */
}

order

.item-1 { order: 2; } /* Displayed second */
.item-2 { order: 1; } /* Displayed first */
.item-3 { order: 3; } /* Displayed third */

align-self

.item {
  align-self: center;     /* Only this item centered on the cross axis */
  align-self: flex-end;   /* Only this item at the end of the cross axis */
}

8. Common Patterns

Perfect Centering

.center {
  display: flex;
  justify-content: center; /* Horizontal center */
  align-items: center;     /* Vertical center */
  height: 100vh;
}

Navigation Bar

.navbar {
  display: flex;
  justify-content: space-between; /* Logo on the left, menu on the right */
  align-items: center;
  padding: 0 20px;
}

Example Files

Open flexbox.html in the examples/ folder to see the navigation bar, the three-column card layout, and vertical centering.

Assignment

Read assignment.md and build a responsive card list.

Example files

Complete, runnable files used in this lesson. Copy them into your project and experiment.

flexbox.htmlHTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Flexbox Layout Practice</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

  <!-- 1. Navigation bar (justify-content: space-between) -->
  <nav class="navbar">
    <div class="nav-logo">FlexBox</div>
    <ul class="nav-menu">
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Portfolio</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
    <button class="nav-btn">Get Started</button>
  </nav>

  <main>

    <!-- 2. Hero section with vertical centering -->
    <section class="hero">
      <div class="hero-content">
        <h1>Perfect layouts<br>built with Flexbox</h1>
        <p>Use justify-content + align-items to achieve full centering.</p>
        <div class="hero-buttons">
          <button class="btn-primary">Get Started</button>
          <button class="btn-secondary">Learn More</button>
        </div>
      </div>
    </section>

    <div class="container">

      <!-- 3. justify-content demo -->
      <section class="demo-section">
        <h2>1. justify-content comparison</h2>
        <div class="justify-demo">
          <div>
            <p class="label">flex-start</p>
            <div class="flex-row justify-start">
              <div class="flex-item">A</div>
              <div class="flex-item">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
          <div>
            <p class="label">center</p>
            <div class="flex-row justify-center">
              <div class="flex-item">A</div>
              <div class="flex-item">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
          <div>
            <p class="label">space-between</p>
            <div class="flex-row justify-between">
              <div class="flex-item">A</div>
              <div class="flex-item">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
          <div>
            <p class="label">space-evenly</p>
            <div class="flex-row justify-evenly">
              <div class="flex-item">A</div>
              <div class="flex-item">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
        </div>
      </section>

      <!-- 4. align-items demo -->
      <section class="demo-section">
        <h2>2. align-items comparison</h2>
        <div class="align-demo">
          <div>
            <p class="label">flex-start</p>
            <div class="flex-row align-start" style="height:100px;">
              <div class="flex-item">A</div>
              <div class="flex-item tall">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
          <div>
            <p class="label">center</p>
            <div class="flex-row align-center" style="height:100px;">
              <div class="flex-item">A</div>
              <div class="flex-item tall">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
          <div>
            <p class="label">flex-end</p>
            <div class="flex-row align-end" style="height:100px;">
              <div class="flex-item">A</div>
              <div class="flex-item tall">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
          <div>
            <p class="label">stretch</p>
            <div class="flex-row align-stretch" style="height:100px;">
              <div class="flex-item">A</div>
              <div class="flex-item">B</div>
              <div class="flex-item">C</div>
            </div>
          </div>
        </div>
      </section>

      <!-- 5. flex-grow demo -->
      <section class="demo-section">
        <h2>3. flex-grow comparison</h2>
        <div class="flex-row grow-demo">
          <div class="flex-item grow-0">grow: 0</div>
          <div class="flex-item grow-1">grow: 1</div>
          <div class="flex-item grow-2">grow: 2</div>
        </div>
      </section>

      <!-- 6. Three-column card layout (flex-wrap) -->
      <section class="demo-section">
        <h2>4. Three-column card layout (flex-wrap: wrap)</h2>
        <p class="desc">Try narrowing the window. flex-wrap wraps the cards automatically.</p>
        <div class="card-grid">
          <div class="card">
            <div class="card-color card-color-1"></div>
            <div class="card-body">
              <h3>Project A</h3>
              <p>A responsive layout project built with Flexbox.</p>
            </div>
          </div>
          <div class="card">
            <div class="card-color card-color-2"></div>
            <div class="card-body">
              <h3>Project B</h3>
              <p>A dashboard built with CSS Grid and Flexbox together.</p>
            </div>
          </div>
          <div class="card">
            <div class="card-color card-color-3"></div>
            <div class="card-body">
              <h3>Project C</h3>
              <p>A portfolio covering the core concepts of responsive web design.</p>
            </div>
          </div>
          <div class="card">
            <div class="card-color card-color-4"></div>
            <div class="card-body">
              <h3>Project D</h3>
              <p>A landing page built with a mobile-first approach.</p>
            </div>
          </div>
          <div class="card">
            <div class="card-color card-color-5"></div>
            <div class="card-body">
              <h3>Project E</h3>
              <p>An interactive UI built with CSS animations and transitions.</p>
            </div>
          </div>
          <div class="card">
            <div class="card-color card-color-6"></div>
            <div class="card-body">
              <h3>Project F</h3>
              <p>A brand page applying typography and color theory.</p>
            </div>
          </div>
        </div>
      </section>

    </div>
  </main>

  <!-- 7. Footer (flex + space-between) -->
  <footer class="footer">
    <div class="footer-inner">
      <span class="footer-logo">FlexBox</span>
      <nav class="footer-nav">
        <a href="#">Privacy</a>
        <a href="#">Terms</a>
        <a href="#">Help</a>
      </nav>
      <span class="footer-copy">&copy; 2025</span>
    </div>
  </footer>

</body>
</html>
style.cssCSS
/* =============================================
   Flexbox layout practice example
   Lesson 05: display:flex / justify-content / align-items / flex-wrap / gap
   ============================================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background-color: #f5f6fa;
  color: #333;
  line-height: 1.6;
}

/* =============================================
   1. Navigation bar
   display:flex + justify-content:space-between + align-items:center
   ============================================= */
.navbar {
  display: flex;                   /* Flex container */
  justify-content: space-between;  /* Place logo / menu / button at both ends */
  align-items: center;             /* Vertical centering */
  padding: 0 32px;
  height: 64px;
  background-color: #2c3e50;
  position: sticky;                /* Stick to the top while scrolling */
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-size: 1.4rem;
  font-weight: 900;
  color: #3498db;
  letter-spacing: -1px;
}

/* Make the ul a flex container to place menu items in a row */
.nav-menu {
  display: flex;            /* Lay out menu items horizontally */
  list-style: none;
  gap: 8px;                 /* Spacing between menu items */
}

.nav-menu a {
  color: #bdc3c7;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background-color 0.2s, color 0.2s;
}

.nav-menu a:hover {
  background-color: rgba(255,255,255,0.1);
  color: white;
}

.nav-btn {
  background-color: #3498db;
  color: white;
  border: none;
  padding: 9px 20px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.nav-btn:hover { background-color: #2980b9; }

/* =============================================
   2. Hero section
   display:flex + justify-content:center + align-items:center
   → Full centering
   ============================================= */
.hero {
  display: flex;
  justify-content: center;  /* Horizontal center */
  align-items: center;      /* Vertical center */
  min-height: 400px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  text-align: center;
  padding: 60px 20px;
}

.hero-content h1 {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 16px;
  line-height: 1.3;
}

.hero-content p {
  font-size: 1.05rem;
  opacity: 0.85;
  margin-bottom: 28px;
}

/* Button group: placed side by side with flex */
.hero-buttons {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.btn-primary {
  background-color: white;
  color: #667eea;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.2s;
}

.btn-primary:hover { transform: scale(1.05); }

.btn-secondary {
  background-color: transparent;
  color: white;
  border: 2px solid rgba(255,255,255,0.6);
  padding: 12px 28px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 0.2s, background-color 0.2s;
}

.btn-secondary:hover {
  border-color: white;
  background-color: rgba(255,255,255,0.1);
}

/* Container */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* Demo section */
.demo-section {
  background: white;
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}

.demo-section h2 {
  font-size: 1.2rem;
  color: #2c3e50;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #667eea;
}

.desc {
  color: #777;
  font-size: 0.88rem;
  margin-bottom: 16px;
}

.label {
  font-size: 0.78rem;
  color: #888;
  margin-bottom: 6px;
  font-family: 'Courier New', monospace;
}

/* =============================================
   3. justify-content demo
   ============================================= */
.justify-demo {
  display: flex;
  flex-direction: column;  /* Stack vertically */
  gap: 16px;
}

/* Shared flex row */
.flex-row {
  display: flex;           /* Flex container */
  background-color: #f0f2f5;
  border-radius: 6px;
  padding: 8px;
  min-height: 50px;
}

.justify-start   { justify-content: flex-start; }
.justify-center  { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-evenly  { justify-content: space-evenly; }

/* Shared flex item */
.flex-item {
  background-color: #667eea;
  color: white;
  font-weight: 700;
  width: 48px;
  height: 48px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.flex-item.tall {
  height: 72px;            /* Item with a different height (for the align-items demo) */
}

/* =============================================
   4. align-items demo
   ============================================= */
.align-demo {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.align-demo > div {
  flex: 1;
  min-width: 180px;
}

.align-start   { align-items: flex-start; }
.align-center  { align-items: center; }
.align-end     { align-items: flex-end; }
.align-stretch { align-items: stretch; }

/* Let items stretch in the stretch example */
.align-stretch .flex-item {
  height: auto;            /* Auto height → stretch effect */
}

/* =============================================
   5. flex-grow demo
   ============================================= */
.grow-demo { gap: 8px; }

.grow-0 { flex-grow: 0; }  /* Takes none of the remaining space */
.grow-1 { flex-grow: 1; }  /* 1/3 of the remaining space */
.grow-2 { flex-grow: 2; }  /* 2/3 of the remaining space */

.grow-0 { background-color: #e74c3c; }
.grow-1 { background-color: #3498db; width: auto; }
.grow-2 { background-color: #27ae60; width: auto; }

/* =============================================
   6. Card grid (flex-wrap: wrap)
   ============================================= */
.card-grid {
  display: flex;       /* Flex container */
  flex-wrap: wrap;     /* Wrap when the screen is narrow */
  gap: 20px;           /* Spacing between cards */
}

.card {
  flex: 1 1 280px;     /* grow:1 shrink:1 basis:280px */
                       /* At least 280px, grows when there is space */
  border-radius: 10px;
  overflow: hidden;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: transform 0.25s, box-shadow 0.25s;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.14);
}

.card-color {
  height: 120px;
}

.card-color-1 { background: linear-gradient(135deg, #667eea, #764ba2); }
.card-color-2 { background: linear-gradient(135deg, #f093fb, #f5576c); }
.card-color-3 { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.card-color-4 { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.card-color-5 { background: linear-gradient(135deg, #fa709a, #fee140); }
.card-color-6 { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }

.card-body {
  padding: 16px;
}

.card-body h3 {
  font-size: 1rem;
  color: #2c3e50;
  margin-bottom: 6px;
}

.card-body p {
  font-size: 0.83rem;
  color: #777;
  line-height: 1.5;
}

/* =============================================
   7. Footer
   display:flex + justify-content:space-between
   ============================================= */
.footer {
  background-color: #2c3e50;
  padding: 20px 32px;
}

.footer-inner {
  display: flex;
  justify-content: space-between;  /* Space out the logo / links / copyright */
  align-items: center;
  max-width: 1000px;
  margin: 0 auto;
}

.footer-logo {
  font-size: 1.1rem;
  font-weight: 900;
  color: #3498db;
}

/* Footer navigation */
.footer-nav {
  display: flex;               /* Lay out links horizontally */
  gap: 20px;
}

.footer-nav a {
  color: #aab7b8;
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}

.footer-nav a:hover { color: white; }

.footer-copy {
  color: #636e72;
  font-size: 0.85rem;
}

Assignment

Assignment — Responsive Card List

Goal

Use flex-wrap to build a card list that wraps automatically as the screen width changes.


Requirements

Card Structure

<div class="card-list">
  <div class="card">
    <div class="card-header">Icon or number</div>
    <div class="card-body">
      <h3>Card title</h3>
      <p>Card description text</p>
    </div>
  </div>
  <!-- Six or more cards -->
</div>

CSS Requirements

Property Requirement
display: flex Applied to the card container
flex-wrap: wrap Wrap to a new line when the screen is narrow
flex: 1 1 280px Cards are at least 280px wide and grow when there is space
gap Appropriate spacing between cards
justify-content flex-start or center

Behavior Requirements

  • Wide screen (900px or more): Three-column layout
  • Medium screen (600–900px): Two-column layout
  • Narrow screen (less than 600px): Single-column layout

Combining flex-wrap: wrap with flex-basis lets you achieve this without media queries.


Checklist

  • Used display: flex and flex-wrap: wrap
  • Set the card size with flex: 1 1 280px (or a similar value)
  • Set the spacing between cards with gap
  • Included six or more cards
  • Cards wrap when the browser window is narrowed
  • Did not use inline CSS

Hint

.card-list {
  display: flex;
  flex-wrap: wrap;          /* Key point: allow wrapping */
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  flex: 1 1 280px;         /* At least 280px, grows when there is space */
  /* Automatically switches between 1 and 3 columns depending on screen width */
}

If you are curious about the answer, refer to the solution/ folder.

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

index.htmlHTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Responsive Card List — Assignment Solution</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

  <header class="page-header">
    <h1>Flexbox Responsive Card List</h1>
    <p>Try narrowing the browser window — flex-wrap handles the wrapping automatically.</p>
  </header>

  <main class="container">

    <!-- Card list: responsive with flex-wrap -->
    <div class="card-list">

      <div class="card">
        <div class="card-header bg-blue">01</div>
        <div class="card-body">
          <h3>HTML Basics</h3>
          <p>The markup language that builds the structure of a web page. You learn tags and attributes.</p>
          <div class="card-footer">
            <span class="tag">Beginner</span>
            <span class="tag">Required</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-purple">02</div>
        <div class="card-body">
          <h3>CSS Styling</h3>
          <p>The style language that adds color, fonts, and layout to HTML elements.</p>
          <div class="card-footer">
            <span class="tag">Beginner</span>
            <span class="tag">Design</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-green">03</div>
        <div class="card-body">
          <h3>JavaScript Basics</h3>
          <p>The programming language that adds dynamic behavior to web pages.</p>
          <div class="card-footer">
            <span class="tag">Junior</span>
            <span class="tag">Programming</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-orange">04</div>
        <div class="card-body">
          <h3>Flexbox Layout</h3>
          <p>Everything about CSS Flexbox for building one-dimensional layouts with ease.</p>
          <div class="card-footer">
            <span class="tag">Intermediate</span>
            <span class="tag">Layout</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-teal">05</div>
        <div class="card-body">
          <h3>CSS Grid</h3>
          <p>The powerful CSS Grid system for building two-dimensional layouts.</p>
          <div class="card-footer">
            <span class="tag">Intermediate</span>
            <span class="tag">Layout</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-pink">06</div>
        <div class="card-body">
          <h3>Responsive Web Design</h3>
          <p>Building websites that look good on every screen, from mobile to desktop.</p>
          <div class="card-footer">
            <span class="tag">Intermediate</span>
            <span class="tag">Responsive</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-blue">07</div>
        <div class="card-body">
          <h3>CSS Animation</h3>
          <p>How to build lively UIs with transition and animation.</p>
          <div class="card-footer">
            <span class="tag">Advanced</span>
            <span class="tag">Animation</span>
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-header bg-purple">08</div>
        <div class="card-body">
          <h3>CSS Variables</h3>
          <p>Building a systematic design system with Custom Properties.</p>
          <div class="card-footer">
            <span class="tag">Intermediate</span>
            <span class="tag">Architecture</span>
          </div>
        </div>
      </div>

    </div>

  </main>

  <footer class="page-footer">
    <p>Flexbox Responsive Card List &copy; 2025</p>
  </footer>

</body>
</html>
style.cssCSS
/* =============================================
   Responsive card list — assignment solution
   Lesson 05: display:flex / flex-wrap / flex-grow / gap
   ============================================= */

/* Global reset */
* {
  box-sizing: border-box; /* Include padding and border in the width */
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background-color: #f0f2f5;
  color: #333;
  line-height: 1.6;
}

/* Header */
.page-header {
  background: linear-gradient(135deg, #667eea, #764ba2); /* Gradient background */
  color: white;
  text-align: center;
  padding: 50px 20px;
}

.page-header h1 {
  font-size: 2rem;
  margin-bottom: 10px;
}

.page-header p {
  opacity: 0.85;
  font-size: 0.95rem;
}

/* Container: max width + centered */
.container {
  max-width: 1100px;
  margin: 0 auto;       /* auto left and right → horizontally centered */
  padding: 40px 20px;
}

/* =============================================
   Card list: Flexbox + flex-wrap
   The key responsive layout
   ============================================= */
.card-list {
  display: flex;            /* Set up the flex container */
  flex-wrap: wrap;          /* Wrap to the next line automatically when the screen is narrow */
  gap: 22px;                /* Spacing between cards (both rows and columns) */
  justify-content: flex-start; /* Align to the left */
}

/* =============================================
   Card: responsive sizing with the flex shorthand
   ============================================= */
.card {
  /* flex: grow shrink basis */
  flex: 1 1 280px;          /* At least 280px, grows when there is space, shrinks when space is tight */
  /* → Automatically switches between 1, 2, and 3 columns depending on screen width */

  background-color: white;  /* White background */
  border-radius: 12px;      /* Rounded corners */
  overflow: hidden;         /* Keep children from spilling outside the corners */
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08); /* Shadow */
  transition: transform 0.25s ease, box-shadow 0.25s ease; /* Prepare for hover */
}

/* Card hover: lifts up and the shadow deepens */
.card:hover {
  transform: translateY(-6px);                       /* Move up 6px */
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);     /* Stronger shadow */
}

/* =============================================
   Card header: color + number
   Center the number with display:flex
   ============================================= */
.card-header {
  height: 100px;             /* Header height */
  display: flex;             /* Use flex to center the number */
  align-items: center;       /* Vertical center */
  justify-content: center;   /* Horizontal center */
  font-size: 2rem;           /* Number size */
  font-weight: 900;
  color: rgba(255, 255, 255, 0.7); /* Semi-transparent white */
  letter-spacing: -1px;
}

/* Header background variants */
.bg-blue   { background: linear-gradient(135deg, #667eea, #764ba2); }
.bg-purple { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }
.bg-green  { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.bg-orange { background: linear-gradient(135deg, #f093fb, #f5576c); }
.bg-teal   { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.bg-pink   { background: linear-gradient(135deg, #fa709a, #fee140); }

/* =============================================
   Card body
   ============================================= */
.card-body {
  padding: 20px;             /* Inner padding */
  display: flex;             /* Stack title, description, and tags vertically */
  flex-direction: column;    /* Vertical direction */
  gap: 10px;                 /* Spacing between each element */
}

/* Card title */
.card-body h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #2c3e50;
}

/* Card description */
.card-body p {
  font-size: 0.85rem;
  color: #777;
  line-height: 1.6;
  flex: 1;                   /* Take the remaining space (pushes the tags down) */
}

/* Card footer: lay out the tags in a row */
.card-footer {
  display: flex;             /* Lay out tags horizontally */
  gap: 6px;                  /* Spacing between tags */
  flex-wrap: wrap;           /* Wrap when there are many tags */
  margin-top: 4px;
}

/* Tags: use flex items instead of inline-block */
.tag {
  padding: 3px 10px;         /* Inner padding */
  border-radius: 20px;       /* Rounded pill shape */
  background-color: #f0f2f5; /* Light background */
  color: #555;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Footer */
.page-footer {
  background-color: #2c3e50;
  color: #aab7b8;
  text-align: center;
  padding: 24px;
  font-size: 0.85rem;
}

Learn this lesson with a mentor

Work through the Build Your Homepage series on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now