Let’s create a Doomsday 3D Card Hover Animation using HTML and CSS – a dark, smoky character card where Doctor Doom steps out of the frame when you hover over it, while the card tilts back in 3D and his name flips up below.
- HTML: Create a simple
figurecard with the Doctor Doom image inside it and afigcaptionfor his name. - CSS: Style the smoky background, the card scene, the 3D tilt with
perspectiveandrotateX, the pop-out effect on the character and the flipping name plate, all with smooth transitions.
This project teaches how to build a 3D card hover animation using HTML and CSS by combining CSS Grid stacking, perspective and rotateX transforms, object-fit image cropping and a ::before pseudo-element for the card background.
HTML :
HTML: Creates the structure of the card with a figure element that holds the Doctor Doom image and a figcaption with his name, and links the Cinzel font and the stylesheet.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Doomsday 3D Card | @coding.stella</title>
<link href="https://fonts.googleapis.com/css2?family=Cinzel:wght@900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<figure>
<img src="./images/doom.png" alt="Doctor Doom">
<figcaption>Doctor Doom</figcaption>
</figure>
</body>
</html>
CSS :
CSS: Sets the smoky page background, uses ::before for the card scene, stacks the image and name with CSS Grid, and on hover tilts the scene back with rotateX(60deg), grows the character out of the card and flips the name plate into view.
body {
--size: min(260px, 33vw, 30vh);
margin: 0;
min-height: 100vh;
display: grid;
grid-auto-flow: column;
grid-auto-columns: var(--size);
place-content: end center;
background:
linear-gradient(#0000, rgb(5 12 8 / 88%)),
url(./images/bg.jpg) center/cover;
}
figure {
width: 100%;
aspect-ratio: 1;
margin: 0 0 60px;
padding: 5px 20px 0;
box-sizing: border-box;
display: grid;
grid-template-rows: 100%;
grid-template-columns: 100%;
cursor: pointer;
position: relative;
filter: drop-shadow(0 0 20px rgb(0 0 0 / 50%));
}
figure::before {
content: "";
position: absolute;
z-index: -1;
inset: 0;
background: url(./images/doom-back.jpg) center/cover;
transform-origin: bottom;
filter: brightness(.9);
transition: .5s;
}
img {
grid-area: 1/1;
width: 100%;
height: 100%;
object-fit: cover;
object-position: top;
filter: contrast(.8) brightness(.7);
place-self: end center;
transition: .5s;
}
figcaption {
grid-area: 1/1;
width: calc(100% + 40px);
font-family: "Cinzel", serif;
font-weight: 900;
color: #fff;
font-size: min(26px, 4.2vmin);
white-space: nowrap;
text-align: center;
place-self: end center;
transform: perspective(500px) translateY(100%) rotateX(-90deg);
backface-visibility: hidden;
transform-origin: top;
background: #000;
transition: .5s;
}
figure:hover img {
width: calc((var(--size) - 5px) * 1.13);
height: calc((var(--size) - 5px) * 2.55);
filter: contrast(1);
}
figure:hover::before {
filter: brightness(.3);
transform: perspective(500px) rotateX(60deg);
}
figure:hover figcaption {
transform: perspective(500px) translateY(100%) rotateX(-30deg);
}
This project demonstrates how HTML and CSS can work together to create a cinematic 3D card hover animation without any JavaScript. With only a few transforms, filters and transitions, Doctor Doom rises out of the card like he is stepping into your screen. Try it with your own favourite character and background to make the effect your own.
If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!
