Yogesh Chauhan's Blog

How to create a flip effect with CSS?

in CSS on March 28, 2021

I’m sure there are multiple ways to do this but here’s one way to do it. The concept is setting the front and back of the card on each other using position:absolute.

Let’s start with a simple HTML elements first.

Let’s adjust the HTML elements with some CSS style.

We’re going to need a container with position:relative and then two sides (front and back) with position:absolute.

Nice. Now, the front and back sides are on top of each other. The next step is to hide the back side.

We are going to use transform property and set it to 180deg for the .column-back. That alone won’t work because it will set a mirror image visible for the back element. We need to hide the mirror image using backface-visibility property.

Just like this:

Since we have set the front and back of the element, what we can do is just rotate the entire element on hover to create the flip effect.

Just like this:

As you can see in the demo above, we see the same image on hover but on the other side as a mirror image. It’s because we haven’t set the backface-visibility property for the front side.

It’s still in the 2D rotation. We need to change it by setting transform-style property to preserve-3d on the main container.

Just like this:

Still, we don’t see the flip because we haven’t set the transform property yet. Let’s do it.

That’s it. There is a flip card ready in the demo above.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
The Sort and Compare Functions in JavaScriptJavaScriptSQL Right JoinSQL/MySQLHow to scroll contents of HTML body horizontally and vertically using JavaScript?JavaScriptHow does AdSense calculate page loading time?JavaScriptHow to Find the Highest (or Lowest) Number in an Array in JavaScript?JavaScriptURL paths in DrupalDrupal