FlipcardTutorials

How to create a Flip card 3D

How to create a Flip card 3D

How to create a Flip card 3D

Before We Start

Every developer needs clean and modern elements to develop their websites, It contains pictures and a user interface element within a website. The most important one and the first section that the user sees when the user enters a website. How to create a Flip card 3D

So if you are a person who wishes to develop a website, you have to know how to create that properly.

How to create a Flip card 3D

We are here to solve your problem. In this article we discuss how to create these elements. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag.

<div class="flip-cards">
  <div class="card-container">
    <div class="card" data-image="https://picsum.photos/300/400">
      <div class="face back">
        <p>Lorem ipsum dolor sit amet, consectetur, adipisicing elit. Iure eligendi sequi non modi quis velit dignissimos, deleniti et accusamus sunt ipsa dolores beatae fugiat id minima veritatis aperiam amet officiis.</p>
      </div>
      <div class="face left"></div>
      <div class="face right"></div>
      <div class="face front">
        <img src="https://picsum.photos/300/400" alt="image" class="image">
      </div>
    </div>  
  </div>
  <div class="card-container">
    <div class="card" data-image="https://picsum.photos/301/400">
      <div class="face back">
        <p>Lorem ipsum dolor sit amet, consectetur, adipisicing elit. Iure eligendi sequi non modi quis velit dignissimos, deleniti et accusamus sunt ipsa dolores beatae fugiat id minima veritatis aperiam amet officiis.</p>
      </div>
      <div class="face left"></div>
      <div class="face right"></div>
      <div class="face front">
        <img src="https://picsum.photos/301/400" alt="image" class="image">
      </div>
    </div>  
  </div>
  <div class="card-container">
    <div class="card" data-image="https://picsum.photos/302/400">
      <div class="face back">
        <p>Lorem ipsum dolor sit amet, consectetur, adipisicing elit. Iure eligendi sequi non modi quis velit dignissimos, deleniti et accusamus sunt ipsa dolores beatae fugiat id minima veritatis aperiam amet officiis.</p>
      </div>
      <div class="face left"></div>
      <div class="face right"></div>
      <div class="face front">
        <img src="https://picsum.photos/302/400" alt="image" class="image">
      </div>
    </div>  
  </div>
</div>

Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag.

<style>
html, body {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
*, *::before, *::after {
  box-sizing: inherit;
}
body {
  display: flex;
  min-height: 100vh;
  background: #111;
}
// flip card
@import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap');
.flip-cards {
  display: flex;
  width: 100%;
  max-width: 900px;
  margin: auto;
  background: rgb(34,34,34);
  background: linear-gradient(0deg, rgba(34,34,34,1) 3%, rgba(34,34,34,0) 74%);
  .card-container {
    position: relative;
    perspective: 1500px;
    width: calc(100% / 3);
    height: 400px;
    margin: auto;
    .card, .face {
      position: absolute;
      width: 100%;
      height: 100%;
      display: grid;
      justify-content: center;
      align-items: center;
      color: #fff;
      background-color: #2c2c54;
      cursor: pointer;
    }
    .card {
      transform-style: preserve-3d;
      transition: transform 1.5s cubic-bezier(0.34, 1.56, 0.64, 1);
      transform: rotateY(-60deg);
      .front {
        backface-visibility: hidden;
        img {
          position: absolute;
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      .back {
        transform: rotateY(180deg) translateZ(10px);
        &:before {
          content: '';
          position: inherit;
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
          margin: auto;
          width: 95%;
          height: 95%;
          border: 1px solid #fff;
        }
        p {
          padding: 20px;
          font-family: 'Raleway', sans-serif;
          font-size: 15px;
          text-align: center;
        }
      }
      .left {
        transform: translateX(-5px) translateZ(-5px) rotateY(-90deg);
        z-index: 5;
        width: 10px;
        background-position: left;
        background-size: cover;
        &:before {
          content: '';
          position: absolute;
          z-index: 1;
          background: rgba(0,0,0,.5);
          width: 100%;
          height: 100%;
          filter: blur(1px);
        }
      }
      .right {
        right: 0;
        transform: translateX(5px) translateZ(-5px) rotateY(90deg);
        width: 10px;
        background-position: right;
        background-size: cover;
        &:before {
          content: '';
          position: absolute;
          z-index: 1;
          background: rgba(0,0,0,.5);
          width: 100%;
          height: 100%;
          filter: blur(1px);
        }
      }
    }
    &:hover {
      .card {
        will-change: transform;
        transform: rotateY(180deg);
      }
    }
  }
} 
</style>

Step 3 – Add JavaScript

And also copy and paste below JavaScript code between <script></script> tag.

<script>
window.addEventListener('load', () => {
  let url = document.querySelectorAll('.card').forEach((item) => {
    item.querySelector('.left').style.backgroundImage = "url("+item.dataset.image+")";
    item.querySelector('.right').style.backgroundImage = "url("+item.dataset.image+")";
  });
});
</script>

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want. Enjoy it.

Your Output

How to create a Flip card 3D

Your Output

How to create a Flip card 3D

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button