Your toolbox so far
color · background-color · width · height
font-size · font-weight · font-family
border-width · border-style · border-color
border-radius · border: none
<div> makes a container
<div>
<h2>Road Racer</h2>
<p>Race through the city!</p>
<button>Play</button>
</div>
id and class label things
<div id="roadRacer" class="gameCard">
<h2 class="gameTitle">Road Racer</h2>
</div>
| id | class |
|---|---|
| Usually one unique thing. | A reusable group. Many things can share it. |
id="player" | class="enemy" |
CSS: #player | CSS: .enemy |
Ten enemies that should share the same style = id or class?
<img> adds an image
<img
src="https://rbscode.com/Student-Portal/images/8.png"
alt="Sports car at night"
>
Two ways to set image width
<img
src="https://rbscode.com/Student-Portal/images/8.png"
alt="Sports car at night"
width="300"
>
Notice: width="300" has no px. In this HTML attribute, the number is treated as pixels.
<img
src="https://rbscode.com/Student-Portal/images/8.png"
alt="Sports car at night"
style="width: 300px;"
>
In CSS, write the unit: width: 300px;. For real projects, CSS is usually the better place for styling.
<style>
.gameImage {
width: 300px;
border-radius: 14px;
}
</style>
<img
class="gameImage"
src="https://rbscode.com/Student-Portal/images/8.png"
alt="Sports car at night"
>
width: 100%; means: fill 100% of the width of the parent container.
.gameImage {
width: 100%;
}
This is extremely useful for cards. We will use percentages properly again in CSS 2. Usually set the image width and let the browser keep its natural height so the image does not get squashed.
Use CSS 1 to make the div into a card
<style>
.gameCard {
width: 300px;
background-color: #111827;
color: white;
border-width: 3px;
border-style: solid;
border-color: #536dfe;
border-radius: 16px;
}
.gameImage {
width: 300px;
border-radius: 12px;
}
.gameTitle {
font-size: 28px;
font-weight: bold;
font-family: Arial;
}
</style>
<div class="gameCard">
<img
class="gameImage"
src="https://rbscode.com/Student-Portal/images/8.png"
alt="Road Racer car"
>
<h2 class="gameTitle">Road Racer</h2>
<p>Race through the city and beat your score!</p>
<button>PLAY</button>
</div>
Make it yours
Copy the card, then change at least 5 things.
Try the background color, border color, border radius, title font size, title font family, card width or image width.
The card is still deliberately simple. CSS 2 adds spacing and layout tools that make cards much more polished.
<a> makes a link
<a href="game.html">Play Road Racer</a>
Open a website in a new tab
<a href="https://rbscode.com" target="_blank">
Open RBS Code
</a>
Great trick: link to a place on the SAME page
<a href="#games">Jump to Games</a>
...
<div id="games">
<h2>Games</h2>
</div>
href="#games" searches this page for id="games" and jumps there.You already used this lesson's real version: Jump to the final build.
id="highScores", then create a link that jumps to it.<br> makes a line break
<p>
Lives: 3<br>
Coins: 12<br>
Level: 2
</p>
<input> lets the player enter something
<p>Player name:</p>
<input type="text" placeholder="Type your name">
It disappears when the user types.
The user can edit it.
<input
type="text"
placeholder="Type your name"
>
<br><br>
<input
type="text"
value="Player 1"
>
Tomorrow's JavaScript can read what is really inside an input using input.value.
Need the number input?
<input type="number" placeholder="Level">Build the Road Racer card
This is the important part. Try to build it from the target first. Look back and copy tags or CSS only when you need them.
Requirements
Use all of these:
div · id · class · img · src · alt · a · href · br · input · placeholder
Also use CSS 1 to style the card, image and title.
Need the basic page shell?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Road Racer</title>
<style>
/* CSS here */
</style>
</head>
<body>
<!-- Build here -->
</body>
</html>Short drills
<img href="8.png"><a ____="game.html">Play</a>id="scores".Can you actually use it?
<div>.id for one unique element and class for a reusable group.src and useful alt text.width="300" or CSS width: 300px;.href.href="#id".<br> for a line break.placeholder vs value.Recognition is not mastery. The checkpoint is passed when you can build with the skill.
Know it already? Prove it, then build.
Complete the checkpoint without notes. If it is easy, skip the repetition and build the larger challenge.
Game Gallery Challenge
Create three game cards using the same reusable classes.
Each card needs an image, title, description and play link. Give every game its own unique id.
At the top, create three same-page links that jump directly to each game. Add a player-name input too.
Use CSS 1 to make the three cards visibly consistent.
Finish cleanly and independently? Move on to CSS 2 or begin connecting the card to JavaScript.