Web development
Top 5 Fan Site
Build a fan page for your five favourite animals, with a header, a menu and cards laid out side by side.
Real websites have a header, a menu, content laid out in a grid and a footer. Today you will build one: a fan site for your top five animals, each on its own card, side by side.
You will learn
- Plan a page with
<header>,<main>and<footer> - Make links that jump to a part of the page
- Lay out cards side by side with flexbox
- Add shadows and a hover effect
You will need
- A computer with a web browser
- The Web Studio, or Notepad
- Days 1 and 2, for HTML and CSS
Words to know
- layout
- How the parts of a page are arranged.
- flexbox
- A CSS layout that puts things in a row and wraps them onto new lines.
- id
- A unique name for one element, such as
id="top5", which a link can jump to. - hover
- Pointing at something with the mouse.
:hoverstyles only apply then.
Step by step
Step 1: Plan the page
In the Web Studio, choose Day 3: Top 5 Fan Site. The page has three parts: a
<header>at the top, the<main>content, and a<footer>at the bottom. The cards will go in the empty<div>calledcards.1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>My Top 5 Animals</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <header>10 <h1>My Top 5 Animals</h1>11 <p>The five best animals on the planet, in my opinion.</p>12 </header>13 <main>14 <h2 id="top5">The top 5</h2>15 <div class="cards">16 17 </div>18 </main>19 <footer>Made by Sam for Coding Club</footer>20 </body>21</html>1body {2 font-family: Arial, sans-serif;3 margin: 0;4 background: #f4f7fb;5}A heading, a line about the page and a footer. Step 2: Five cards
Each animal gets a
<div class="card">: a box holding an emoji, a name and a fact. Fill in all five. They stack one under another for now.New: lines 16 to 40.
1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>My Top 5 Animals</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <header>10 <h1>My Top 5 Animals</h1>11 <p>The five best animals on the planet, in my opinion.</p>12 </header>13 <main>14 <h2 id="top5">The top 5</h2>15 <div class="cards">16 <div class="card">17 <div class="emoji">🦊</div>18 <h3>Fox</h3>19 <p>A fox's bushy tail is called a brush, and it wraps it round itself to keep warm.</p>20 </div>21 <div class="card">22 <div class="emoji">🐙</div>23 <h3>Octopus</h3>24 <p>An octopus has three hearts and blue blood.</p>25 </div>26 <div class="card">27 <div class="emoji">🦦</div>28 <h3>Sea otter</h3>29 <p>Sea otters sometimes hold hands while they sleep, so they do not drift apart.</p>30 </div>31 <div class="card">32 <div class="emoji">🐧</div>33 <h3>Emperor penguin</h3>34 <p>Emperor penguins can dive more than 500 metres deep.</p>35 </div>36 <div class="card">37 <div class="emoji">🦉</div>38 <h3>Owl</h3>39 <p>An owl cannot move its eyes, so it turns its whole head instead.</p>40 </div>41 </div>42 </main>43 <footer>Made by Sam for Coding Club</footer>44 </body>45</html>Five animals, one under another. Step 3: A header and a menu
Colour the header, and add a
<nav>menu with two links.href="#top5"jumps to the element withid="top5". Add a section at the bottom for the second link to jump to.New: lines 12 to 15, 46 and 47.
1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>My Top 5 Animals</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <header>10 <h1>My Top 5 Animals</h1>11 <p>The five best animals on the planet, in my opinion.</p>12 <nav>13 <a href="#top5">Top 5</a>14 <a href="#vote">Vote</a>15 </nav>16 </header>17 <main>18 <h2 id="top5">The top 5</h2>19 <div class="cards">20 <div class="card">21 <div class="emoji">🦊</div>22 <h3>Fox</h3>23 <p>A fox's bushy tail is called a brush, and it wraps it round itself to keep warm.</p>24 </div>25 <div class="card">26 <div class="emoji">🐙</div>27 <h3>Octopus</h3>28 <p>An octopus has three hearts and blue blood.</p>29 </div>30 <div class="card">31 <div class="emoji">🦦</div>32 <h3>Sea otter</h3>33 <p>Sea otters sometimes hold hands while they sleep, so they do not drift apart.</p>34 </div>35 <div class="card">36 <div class="emoji">🐧</div>37 <h3>Emperor penguin</h3>38 <p>Emperor penguins can dive more than 500 metres deep.</p>39 </div>40 <div class="card">41 <div class="emoji">🦉</div>42 <h3>Owl</h3>43 <p>An owl cannot move its eyes, so it turns its whole head instead.</p>44 </div>45 </div>46 <h2 id="vote">Which is your favourite?</h2>47 <p>Tell me at Coding Club, and I might change my list!</p>48 </main>49 <footer>Made by Sam for Coding Club</footer>50 </body>51</html>New: lines 6 to 18.
1body {2 font-family: Arial, sans-serif;3 margin: 0;4 background: #f4f7fb;5}6 7header {8 background: #1e5fa8;9 color: white;10 text-align: center;11 padding: 24px;12}13 14nav a {15 color: white;16 margin: 0 12px;17 font-weight: bold;18}A blue header with a menu. Step 4: Side by side
Flexbox lays things out in a row.
display: flexon thecardsbox puts the cards side by side,flex-wrap: wraplets them move onto the next line when there is no room, andgapspaces them out.New: lines 19 to 32.
1body {2 font-family: Arial, sans-serif;3 margin: 0;4 background: #f4f7fb;5}6 7header {8 background: #1e5fa8;9 color: white;10 text-align: center;11 padding: 24px;12}13 14nav a {15 color: white;16 margin: 0 12px;17 font-weight: bold;18}19 20main {21 padding: 20px;22}23 24.cards {25 display: flex;26 flex-wrap: wrap;27 gap: 16px;28}29 30.card {31 width: 170px;32}The cards sit side by side and wrap onto a new line. Step 5: Make them look like cards
A white background, rounded corners and a soft shadow make each box look like a card. Make the emoji big.
rgba(0, 0, 0, 0.15)is black at 15% strength, a light shadow.New: lines 32 to 36 and 38 to 41.
1body {2 font-family: Arial, sans-serif;3 margin: 0;4 background: #f4f7fb;5}6 7header {8 background: #1e5fa8;9 color: white;10 text-align: center;11 padding: 24px;12}13 14nav a {15 color: white;16 margin: 0 12px;17 font-weight: bold;18}19 20main {21 padding: 20px;22}23 24.cards {25 display: flex;26 flex-wrap: wrap;27 gap: 16px;28}29 30.card {31 width: 170px;32 background: white;33 border-radius: 14px;34 padding: 14px;35 text-align: center;36 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);37}38 39.emoji {40 font-size: 64px;41}Proper cards, with shadows. Step 6: Lift on hover
transform: translateY(-6px)moves a card up 6 pixels, but only while the mouse is over it.transitionmakes the move smooth instead of a jump. Finish with a footer style.New: lines 32 and 43 to 53.
1body {2 font-family: Arial, sans-serif;3 margin: 0;4 background: #f4f7fb;5}6 7header {8 background: #1e5fa8;9 color: white;10 text-align: center;11 padding: 24px;12}13 14nav a {15 color: white;16 margin: 0 12px;17 font-weight: bold;18}19 20main {21 padding: 20px;22}23 24.cards {25 display: flex;26 flex-wrap: wrap;27 gap: 16px;28}29 30.card {31 width: 170px;32 transition: transform 0.2s;33 background: white;34 border-radius: 14px;35 padding: 14px;36 text-align: center;37 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);38}39 40.emoji {41 font-size: 64px;42}43 44.card:hover {45 transform: translateY(-6px);46 box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);47}48 49footer {50 text-align: center;51 padding: 16px;52 color: #555555;53}Point at a card: it lifts up. Try the menu links too.
Test it
Tick each one when it works. If one does not, look back at the step it comes from.
Stretch challenges
Finished early? Try these. Each one has a hint if you get stuck.
Your own top 5
Change the page to your own top five: films, games, foods or footballers.
Show a hint
Change the text in each card, and pick new emoji. Keep the
classnames the same so the styles still work.Number them
Put a coloured number badge, 1 to 5, in the corner of each card.
Show a hint
Add
<span class="rank">1</span>to each card. Give.cardposition: relative, and.rankposition: absolute; top: 8px; left: 8px;with a background and aborder-radius.A favourite
Make your number 1 card stand out from the rest.
Show a hint
Give it a second class,
class="card top", then style.topwith a gold border.
The finished code
Show the whole page
1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>My Top 5 Animals</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <header>10 <h1>My Top 5 Animals</h1>11 <p>The five best animals on the planet, in my opinion.</p>12 <nav>13 <a href="#top5">Top 5</a>14 <a href="#vote">Vote</a>15 </nav>16 </header>17 <main>18 <h2 id="top5">The top 5</h2>19 <div class="cards">20 <div class="card">21 <div class="emoji">🦊</div>22 <h3>Fox</h3>23 <p>A fox's bushy tail is called a brush, and it wraps it round itself to keep warm.</p>24 </div>25 <div class="card">26 <div class="emoji">🐙</div>27 <h3>Octopus</h3>28 <p>An octopus has three hearts and blue blood.</p>29 </div>30 <div class="card">31 <div class="emoji">🦦</div>32 <h3>Sea otter</h3>33 <p>Sea otters sometimes hold hands while they sleep, so they do not drift apart.</p>34 </div>35 <div class="card">36 <div class="emoji">🐧</div>37 <h3>Emperor penguin</h3>38 <p>Emperor penguins can dive more than 500 metres deep.</p>39 </div>40 <div class="card">41 <div class="emoji">🦉</div>42 <h3>Owl</h3>43 <p>An owl cannot move its eyes, so it turns its whole head instead.</p>44 </div>45 </div>46 <h2 id="vote">Which is your favourite?</h2>47 <p>Tell me at Coding Club, and I might change my list!</p>48 </main>49 <footer>Made by Sam for Coding Club</footer>50 </body>51</html>1body {2 font-family: Arial, sans-serif;3 margin: 0;4 background: #f4f7fb;5}6 7header {8 background: #1e5fa8;9 color: white;10 text-align: center;11 padding: 24px;12}13 14nav a {15 color: white;16 margin: 0 12px;17 font-weight: bold;18}19 20main {21 padding: 20px;22}23 24.cards {25 display: flex;26 flex-wrap: wrap;27 gap: 16px;28}29 30.card {31 width: 170px;32 transition: transform 0.2s;33 background: white;34 border-radius: 14px;35 padding: 14px;36 text-align: center;37 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);38}39 40.emoji {41 font-size: 64px;42}43 44.card:hover {45 transform: translateY(-6px);46 box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);47}48 49footer {50 text-align: center;51 padding: 16px;52 color: #555555;53}Notes for the teacher
Timing
- 10 minutes: step 1. Sketch the page's boxes on the board: header, main, cards, footer.
- 25 minutes: steps 2 to 4. Flexbox is the big idea: try changing the width of the preview to watch the cards wrap.
- 15 minutes: steps 5 and 6, the tests, then students make it their own.
Mistakes to look out for
- A card's
</div>missing: the cards nest inside each other and the layout goes strange. display: flexon.cardinstead of.cards: it is the box holding the cards that lays them out.href="top5"without the #: the link looks for a page called top5 instead of jumping down.- Facts copied from the internet without checking: a good moment to talk about reliable sources.
Going further
Narrow the window and watch the cards move onto new lines: this is responsive design, the same page working on a phone and a computer.