YogeshChauhan.com

How to create a flip effect with CSS?

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.

dreamhost

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 uninstall Cocoapods from the Mac OS? #4 How to Use SQL MAX() Function with Dates? #5 How to add Read More Read Less Button using JavaScript? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Apr 7 Solution for “Yarn build: Failed because of a stylelint error” Apr 7 Make sure your links have descriptive text Apr 7 How to add Laravel to WordPress using Sage theme (and install Tailwind CSS)? Apr 2 How to create a sidebar using pure CSS? Apr 1 How to switch dark and light themes using pure CSS? Apr 1 How to calculate elapsed time in JavaScript?

You might also like these

How to refresh a page using PHP at regularly occurring intervals?PHPThe Drupal flowDrupalHow to change the style for checked radio button or checkboxes using CSS?CSSWordPress 5.7 is migrating to latest jQuery version and people are freaking outjQueryCSS Overflow Property with ExamplesCSSThe Difference Between Arrays and Objects in JavaScriptJavaScript