Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Have you ever flipped over your school ID card hanging on your lanyard? On the front face, you see your photograph, student name, and class section. But when you flip the card over, the back face reveals your emergency contact numbers, blood group, and residential address. Or think of flashcards used by students preparing for the CBSE or JEE exams: the question is on the front, and the step-by-step solution is printed on the back.
In this chapter, we will bring together perspective, preserve-3d, rotateY, translateZ, and backface-visibility to build the crown jewel of CSS 3D interactions: the Complete 3D Flipping Card.
Building a true 3D flipping card requires a precise 3-layer DOM hierarchy:
+-------------------------------------------------------------------------+ | THE 3-LAYER FLIP CARD ARCHITECTURE | +-------------------------------------------------------------------------+ LAYER 1: SCENE CONTAINER (perspective: 1000px) +-----------------------------------------------------------------------+ | | | LAYER 2: FLIPPER SHELL (transform-style: preserve-3d; | | transition: transform 0.7s) | | +-----------------------------------------------------------------+ | | | | | | | LAYER 3A: FRONT FACE LAYER 3B: BACK FACE | | | | (backface-visibility: hidden) (backface-visibility: | | | | hidden; | | | | [Student Photo & Name] transform: rotateY(180deg)| | | | | | | | [Blood Group & Contacts] | | | +-----------------------------------------------------------------+ | | | +-----------------------------------------------------------------------+
.flip-scene): Must define perspective to create camera depth..flip-card): Holds transform-style: preserve-3d; and transitions transform..face-front, .face-back): Must have position: absolute; width: 100%; height: 100%; and backface-visibility: hidden;.180deg (transform: rotateY(180deg);) so that when the flipper rotates, the back face faces forward legibly!backface-visibilityBy default, HTML elements are transparent from behind: if you rotate a <div> 180 degrees, you see its backwards mirror image shining through like transparent tracing paper.
Setting backface-visibility: hidden; instructs the browser:
translateZ During FlipsTo make your 3D card look like a high-end physical object rather than a flat piece of paper, you can push the text or profile image outward along the $Z$-axis so it floats above the card surface:
Whenever you write multiple transform functions:
The browser multiplies these matrices together into a single $4 \times 4$ homogeneous transformation matrix:
$$\begin{bmatrix} m_{11} & m_{12} & m_{13} & m_{14} \\ m_{21} & m_{22} & m_{23} & m_{24} \\ m_{31} & m_{32} & m_{33} & m_{34} \\ m_{41} & m_{42} & m_{43} & m_{44} \end{bmatrix}$$
In CSS, you can inspect this matrix using window.getComputedStyle(element).transform, which returns a matrix3d(...) string containing 16 numbers. While writing raw matrix3d() manually is rarely necessary, understanding this matrix explains why transforms are calculated almost instantly on your device's GPU!
On touchscreen devices (smartphones and tablets), the :hover pseudo-class can behave unpredictably.
Use a tiny JavaScript event listener to toggle an .is-flipped CSS class on click/touch:
| Practice | Bad Approach | Good Approach | Why It Matters |
|---|---|---|---|
| Back Face Pre-Rotation | Forgetting transform: rotateY(180deg) on .face-back | Pre-rotating the back face by 180deg | Without pre-rotation, the back face text displays mirrored and backwards! |
| Backface Visibility | Leaving default backface-visibility: visible; | Setting backface-visibility: hidden; on both faces | Prevents the front and back faces from overlapping and showing through each other. |
| Vendor Prefixing | Omitting -webkit-backface-visibility | Adding -webkit-backface-visibility: hidden; | Required for smooth rendering on Apple iOS Safari and macOS. |
| Parent Overflow | Setting overflow: hidden; on the scene or flipper | Keeping overflow: visible; | overflow: hidden clips 3D layers and frequently breaks 3D contexts in Chrome and Safari! |
perspective) $\rightarrow$ Inner Flipper (preserve-3d) $\rightarrow$ Two Faces (backface-visibility: hidden).transform: rotateY(180deg) in its default state.rotateY(180deg) on hover or touch.overflow: hidden: overflow: hidden flattens 3D children and cancels transform-style: preserve-3d.-webkit-backface-visibility: hidden;.transform: rotateY(180deg) to the back face of a 3D flip card in its default state?backface-visibility: hidden; necessary on both the front and back card faces?transform-style: preserve-3d?Build an interactive 3D Flashcard for school biology students:
translateZ.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.