UNIT 9 • STAGE 7 OF 7

CSS Transitions

Add hover animations that make the page feel alive

UNIT
STEP 1

What Is a CSS Transition?

A CSS transition tells the browser: when a property changes, do not snap to the new value instantly. Instead, animate the change smoothly over a set amount of time.

Right now your cards appear and disappear abruptly when you hover over them (because there is no hover state yet). After this stage, hovering a card will cause it to gently rise and cast a deeper shadow, then settle back down when you move away. Hover over the cards below:

Food Security Hover over me
Seed Sovereignty Hover over me
Seven Generations Hover over me

That lift effect is built with two CSS properties: transition and transform.

  • transition, tells the browser to animate changes to specific properties over a duration with a timing curve
  • transform: translateY(-4px), moves the element 4 pixels upward. Combined with a transition, this creates the lift
  • box-shadow, a shadow around the card that deepens on hover, reinforcing the sense of the card lifting off the page
STEP 2

Add Transitions to Concept Cards

Find the .concept-card rule in your <style> block. You will modify it to add a transition, then add a new :hover rule below it:

👉 Find .concept-card and add the transition property to it: .concept-card {
  background: white;
  border-left: 4px solid #2d4a1e;
  padding: 24px;
  flex: 1 1 220px;
  border-radius: 8px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
👉 Add this new rule just below .concept-card: .concept-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}
STEP 3

Add Transitions to Recipe Cards

Do the same for the recipe cards. Find .recipe-card and add the transition, then add the :hover rule below it:

👉 Find .recipe-card and add the transition property to it: .recipe-card {
  background: white;
  border-top: 4px solid #8B4513;
  padding: 28px;
  flex: 1 1 280px;
  border-radius: 8px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
👉 Add this new rule just below .recipe-card: .recipe-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}
STEP 4

Why These Values?

  • transition: transform 0.3s ease, box-shadow 0.3s ease, the three parts are: what to animate (transform and box-shadow), how long (0.3 seconds), and the timing curve (ease, which starts fast and slows near the end). 0.3s is a widely used default: fast enough to feel responsive, slow enough to be visible.
  • transform: translateY(-4px), moves the card 4 pixels upward along the Y axis. Negative values move up; positive values move down. This is the CSS way to lift a card without affecting its space in the layout: other cards do not reflow when one lifts.
  • box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1), a soft shadow that appears below the card when hovered. The four values are: horizontal offset (0), vertical offset (8px below), blur radius (20px wide), and color (10% opacity black). A deeper, wider shadow on hover reinforces the visual metaphor of the card lifting toward the viewer.
  • The transition must be on the base rule (not the :hover rule) for the animation to play both on mouse-enter and mouse-leave. If you put it only on :hover, the card snaps back instantly when you move away.
STEP 5

Test Your Transitions

In the live preview, scroll to the pillars section and hover slowly over each concept card. You should see each card lift upward and cast a deeper shadow, then settle back when you move away. Do the same for the recipe cards.

If the transition feels too fast or too slow

Try changing 0.3s to 0.5s for a slower, more deliberate lift, or 0.15s for a snappier feel. The timing is a design choice: match it to the personality of the page.

Unit 9 Complete!

You built a full food sovereignty resource page: a hero with research, four concept cards in a Flexbox layout, two recipe cards with ingredient lists, a styled HTML form with CSS focus states, a JavaScript interaction that responds to form submission, polish with spacing and a footer, and CSS transitions that bring the whole page to life. You wrote your first JavaScript. The page responds to the people who use it. That is a meaningful thing to have built.

Code Editor
Live Preview