Flip It Like a Pro: CSS3 Rotating Cards Made Easy

Sandeep RanaSandeep Rana
2 min read

Introduction

Ever feel like your website could use a little pizzazz? Like, ‘Hey, look at me—I’m interactive and stylish!’ Well, say hello to rotating cards in CSS! These little wonders can take your design from ‘meh’ to ‘whoa!’ faster than you can say ‘transform: rotateY(180deg).’

In this blog, I’ll show you how to create these magical flipping cards that’ll make your users go, ‘Wow, this developer knows their stuff!’ And don’t worry—no complicated wizardry is required, just some simple HTML and CSS. Let’s get flipping!"

Prerequisites

  1. Basics of HTML5

  2. Basics of CSS3

Let's code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rotating Cards</title>
    <link rel="stylesheet" href="./style.css" />
</head>

<body>


    <div class="card">
        <div class="card__side card__side--front">
            <h2 class="card__text">Front</h2>
        </div>
        <div class="card__side card__side--back">
            <h2 class="card__text">Back</h2>


        </div>
    </div>

</body>

</html>
:root {
  --gradient-front: linear-gradient(
    to right bottom,
    rgba(46, 204, 113, 1),
    rgba(39, 174, 96, 1)
  );
  --gradient-back: linear-gradient(
    to right bottom,
    rgba(155, 89, 182, 1),
    rgba(142, 68, 173, 1)
  );
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.card {
  margin: auto;
  margin-top: 20px;
  height: 100%;
  width: 300px;
  perspective: 15000rem;
  -moz-perspective: 150rem;
  position: relative;
}

.card__side {
  height: 300px;
  width: inherit;
  transition: all 5s ease-in-out; /* reduce time to make the transition go more faster*/
  position: absolute;
  top: 0;
  left: 0;
  backface-visibility: hidden;
}

.card__side--front {
  background: var(--gradient-front);
  z-index: 1;
}

.card__side--back {
  background: var(--gradient-back);
  transform: rotateY(180deg);
  z-index: -1;
}

.card:hover .card__side--front {
  transform: rotateY(180deg);
  z-index: -1;
}

.card:hover .card__side--back {
  transform: rotateY(0);
  z-index: 1;
}

.card__text {
  color: white !important;
  font-size: 40px;
  text-align: center;
  margin: 50px 0;
}

Helpful Links

GitHub Repo

0
Subscribe to my newsletter

Read articles from Sandeep Rana directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sandeep Rana
Sandeep Rana

I'm a dedicated ServiceNow Developer and Analyst with four years of experience. I previously worked at Deloitte and am currently with QBRAINX. My journey in technology started as a freelance web developer, where I developed a passion for creating user-friendly web solutions. In my current role, I specialize in various aspects of ServiceNow, including Portal design, Flow, Integration, Common Configuration, and HRSD modules. What truly excites me is experimenting with the amalgamation of web development and ServiceNow capabilities. My work allows me to blend creativity with technical prowess, ensuring the solutions I create are both functional and intuitive. I bridge the gap between complex technical concepts and user-friendly designs, striving for excellence in every project. Beyond my professional endeavors, I'm a lifelong learner, constantly exploring new technological horizons. My enthusiasm for innovation fuels my commitment to delivering high-quality results. If you share a passion for technology and innovation, I'd love to collaborate and create something extraordinary together. Let's connect!