Skip to content

3D Effects

The 3D effects of the Casoon UI Library offer a comprehensive collection of CSS transformations and perspective effects that give your UI elements spatial depth and dimensional interest.

Overview

The 3D effects are performance-optimized and respect user preferences for reduced motion. They can be used to position, rotate, tilt, and transform elements in 3D space.

Installation

Import the 3D effects modules via CSS:

css
@import '@casoon/ui-lib/effects/3d.css';

Available Classes

Basic 3D Transformations

ClassDescription
.transform-3dEnables 3D transformations for child elements
.perspectiveDefines a perspective for better 3D effects
.preserve-3dPreserves the 3D position of child elements

Rotation Effects

ClassDescription
.rotate-3dRotation in all three dimensions
.rotate-xRotation around the X-axis
.rotate-yRotation around the Y-axis
.rotate-zRotation around the Z-axis (normal 2D rotation)

Flip Effects

ClassDescription
.flip-3dFlipping an element in 3D space (card flip effect)
.flip-xHorizontal flip effect
.flip-yVertical flip effect

Scaling Effects

ClassDescription
.scale-3dScaling in all three dimensions
.scale-zScaling along the Z-axis for depth effects

Transform Origin

ClassDescription
.origin-centerTransform origin in the center (default)
.origin-topTransform origin at the top
.origin-bottomTransform origin at the bottom
.origin-leftTransform origin on the left
.origin-rightTransform origin on the right

Examples

Simple 3D Rotation

html
<div class="transform-3d perspective">
  <div class="rotate-y" style="--rotate-y-deg: 30deg;">
    I'm rotated 30 degrees around the Y-axis
  </div>
</div>

3D Flip Card

html
<div class="flip-container transform-3d perspective">
  <div class="flip-inner">
    <div class="flip-front">Front of the card</div>
    <div class="flip-back">Back of the card</div>
  </div>
</div>

<style>
  .flip-container {
    width: 300px;
    height: 200px;
  }
  
  .flip-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.8s;
    transform-style: preserve-3d;
  }
  
  .flip-container:hover .flip-inner {
    transform: rotateY(180deg);
  }
  
  .flip-front, .flip-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
  }
  
  .flip-front {
    background-color: var(--color-primary-100);
  }
  
  .flip-back {
    background-color: var(--color-primary-200);
    transform: rotateY(180deg);
  }
</style>

3D Cube

html
<div class="cube-container transform-3d perspective">
  <div class="cube">
    <div class="cube-face cube-face-front">Front</div>
    <div class="cube-face cube-face-back">Back</div>
    <div class="cube-face cube-face-right">Right</div>
    <div class="cube-face cube-face-left">Left</div>
    <div class="cube-face cube-face-top">Top</div>
    <div class="cube-face cube-face-bottom">Bottom</div>
  </div>
</div>

<style>
  .cube-container {
    width: 200px;
    height: 200px;
    perspective: 800px;
  }
  
  .cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1s;
  }
  
  .cube-container:hover .cube {
    transform: rotateY(180deg) rotateX(180deg);
  }
  
  .cube-face {
    position: absolute;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 0, 0, 0.1);
  }
  
  .cube-face-front  { background: rgba(255, 0, 0, 0.2); transform: rotateY(0deg) translateZ(100px); }
  .cube-face-back   { background: rgba(0, 255, 0, 0.2); transform: rotateY(180deg) translateZ(100px); }
  .cube-face-right  { background: rgba(0, 0, 255, 0.2); transform: rotateY(90deg) translateZ(100px); }
  .cube-face-left   { background: rgba(255, 255, 0, 0.2); transform: rotateY(-90deg) translateZ(100px); }
  .cube-face-top    { background: rgba(0, 255, 255, 0.2); transform: rotateX(90deg) translateZ(100px); }
  .cube-face-bottom { background: rgba(255, 0, 255, 0.2); transform: rotateX(-90deg) translateZ(100px); }
</style>

Customization

The 3D effects can be customized via CSS variables:

css
:root {
  --perspective-depth: 1000px;
  --rotate-x-deg: 45deg;
  --rotate-y-deg: 45deg;
  --rotate-z-deg: 45deg;
  --rotate-3d-x: 1;
  --rotate-3d-y: 1;
  --rotate-3d-z: 1;
  --rotate-3d-deg: 45deg;
  --scale-3d-x: 1.5;
  --scale-3d-y: 1.5;
  --scale-3d-z: 1.5;
}

Accessibility

To improve accessibility, the 3D effects respect the user setting prefers-reduced-motion:

css
@media (prefers-reduced-motion: reduce) {
  .rotate-3d,
  .rotate-x,
  .rotate-y,
  .rotate-z,
  .flip-3d,
  .flip-x,
  .flip-y {
    transition: none !important;
    animation: none !important;
  }
}

Browser Support

The 3D effects are supported by all modern browsers. For older browsers, a fallback to 2D transformations is provided.