ุงู†ุชู‚ู„ ู„ู„ู…ุญุชูˆู‰
Robo EgyptRobo Egypt
โ˜ฐ Course contents
Robo Web: home
0. Lab tour1
1. HTML: the page's content7
2. CSS: the page's look6
3. JavaScript: the actions7
4. The project: the to-do list3
5. Pro CSS: shadows and movement5
6. Arrays and building the page with code3
7. Events and forms3
8. Objects and time3
9. Canvas: drawing and games3
10. The final project: the memory game3

๐Ÿ› ๏ธ Section project: a card that flips

Section 5: Pro CSS: shadows and movementLesson 5.5 ยท โฑ 12 min
๐ŸŽฏ Project goal
A card with โ“ on it, and when the mouse is over it, it flips and shows its back: ๐Ÿฆ Lion.
  • perspective gives a feeling of depth, as if the card is in space.
  • The two faces are on top of each other (position: absolute), and the back is turned round from the start: rotateY(180deg).
  • backface-visibility: hidden hides the back of each face.
  • When the mouse is over it we turn the inside box 180 degrees.
HTML
<div class="card">
  <div class="inner">
    <div class="front">โ“</div>
    <div class="back">๐Ÿฆ Lion</div>
  </div>
</div>
CSS
body { font-family: Tahoma, sans-serif; display: flex; justify-content: center; padding-top: 24px; }
.card { width: 160px; height: 200px; perspective: 600px; }
.inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.card:hover .inner { transform: rotateY(180deg); }
.front, .back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border-radius: 16px;
  backface-visibility: hidden;
}
.front { background: #2557c9; color: white; }
.back { background: #ffd23f; font-size: 30px; transform: rotateY(180deg); }
๐Ÿ–ฅ๏ธ The page in Robo Web:The page in Robo Web
๐Ÿ–ฅ๏ธ What happens on the stage?
In the picture the mouse is over the card, and it flipped and showed the lion.
  1. Make three cards side by side for three animals.
  2. Make it flip up and down: rotateX instead of rotateY.

๐Ÿ“Œ Another example: a question card that flips when clicked

Instead of the mouse going over it: clicking adds a class called flipped, and the card flips.

๐ŸŒ A question card that flips when clicked
HTML
<div class="card">
  <div class="inner">
    <div class="front">5 ร— 7 ?</div>
    <div class="back">35 โœ…</div>
  </div>
</div>
CSS
body { font-family: Tahoma, sans-serif; display: flex; justify-content: center; padding-top: 24px; }
.card { width: 160px; height: 200px; perspective: 600px; }
.inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.card.flipped .inner { transform: rotateY(180deg); }
.front, .back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border-radius: 16px;
  backface-visibility: hidden;
}
.front { background: #2557c9; color: white; }
.back { background: #ffd23f; font-size: 26px; transform: rotateY(180deg); }
JavaScript
const card = document.querySelector(".card");
card.onclick = function () {
  card.classList.toggle("flipped");
};
๐Ÿ–ฅ๏ธ The page in Robo Web:The page in Robo Web
โœ๏ธ Practise
Try the example here: copy the code into its tabs, change it, and watch the page change.
โœ๏ธ Practise here in the lessonor open the lab in a new page โ†—

๐ŸŽฏ Challenge yourself

Easy

Change the two faces: ๐ŸŒ on the front and โ€œThe Earthโ€ on the back.

๐Ÿ‘€ Show the solution
๐ŸŒ Solution
HTML
<div class="card">
  <div class="inner">
    <div class="front">๐ŸŒ</div>
    <div class="back">The Earth</div>
  </div>
</div>
CSS
body { font-family: Tahoma, sans-serif; display: flex; justify-content: center; padding-top: 24px; }
.card { width: 160px; height: 200px; perspective: 600px; }
.inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.card:hover .inner { transform: rotateY(180deg); }
.front, .back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border-radius: 16px;
  backface-visibility: hidden;
}
.front { background: #2557c9; color: white; }
.back { background: #ffd23f; font-size: 26px; transform: rotateY(180deg); }
๐Ÿ–ฅ๏ธ The page in Robo Web:The page in Robo Web

Result: it flips and shows โ€œThe Earthโ€.

Medium

The card flips from top to bottom (rotateX).

๐Ÿ‘€ Show the solution
๐ŸŒ Solution
HTML
<div class="card">
  <div class="inner">
    <div class="front">โ“</div>
    <div class="back">๐Ÿฌ Dolphin</div>
  </div>
</div>
CSS
body { font-family: Tahoma, sans-serif; display: flex; justify-content: center; padding-top: 24px; }
.card { width: 160px; height: 200px; perspective: 600px; }
.inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.card:hover .inner { transform: rotateX(180deg); }
.front, .back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border-radius: 16px;
  backface-visibility: hidden;
}
.front { background: #2557c9; color: white; }
.back { background: #ffd23f; font-size: 26px; transform: rotateX(180deg); }
๐Ÿ–ฅ๏ธ The page in Robo Web:The page in Robo Web

Result: it flips up and down.

Hard

Three question-and-answer cards in a row, each flips on its own.

๐Ÿ‘€ Show the solution
๐ŸŒ Solution
HTML
<div class="row">
<div class="card">
    <div class="inner">
      <div class="front">2 + 2</div>
      <div class="back">4</div>
    </div>
  </div>
  <div class="card">
    <div class="inner">
      <div class="front">3 ร— 3</div>
      <div class="back">9</div>
    </div>
  </div>
  <div class="card">
    <div class="inner">
      <div class="front">10 โˆ’ 4</div>
      <div class="back">6</div>
    </div>
  </div>
  </div>
CSS
body { font-family: Tahoma, sans-serif; padding-top: 24px; }
.row { display: flex; gap: 12px; justify-content: center; }
.card { width: 110px; height: 140px; perspective: 600px; }
.inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.card:hover .inner { transform: rotateY(180deg); }
.front, .back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border-radius: 16px;
  backface-visibility: hidden;
}
.front { background: #2557c9; color: white; }
.back { background: #ffd23f; font-size: 26px; transform: rotateY(180deg); }
.front { font-size: 24px; }
๐Ÿ–ฅ๏ธ The page in Robo Web:The page in Robo Web

Result: only the middle card flips.

Finished the lesson? Mark it so your progress counts.