Animation CSS 3D

Berikut adalah panduan lengkap dan contoh praktis membuat animasi CSS 3D. Saya sertakan contoh 3D rotate, flip, card animation, dan cube animation — semua memakai CSS murni.

 

🎨 1. Dasar-dasar CSS 3D

Agar elemen bisa dianimasikan dalam 3D, pastikan:

Container harus punya perspective

.container {
  perspective: 800px;
}

Elemen harus punya transform-style: preserve-3d

.box {
  transform-style: preserve-3d;
}

Gunakan transform 3D

  • rotateX()

  • rotateY()

  • rotateZ()

  • translateZ()

 

🔄 2. Contoh 3D Rotate (Hover)

CSS 3D
.container {
  perspective: 800px;
  width: 200px;
  height: 200px;
}

.card {
  width: 100%;
  height: 100%;
  background: #4a90e2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
  border-radius: 10px;
  transition: transform .7s;
  transform-style: preserve-3d;
}

.container:hover .card {
  transform: rotateY(180deg);
}

 

🃏 3. Contoh 3D Flip Card (Depan & Belakang)

Depan
Belakang
.flip-container {
  width: 220px;
  height: 200px;
  perspective: 800px;
}

.flip-card {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 1s;
  transform-style: preserve-3d;
}

.flip-container:hover .flip-card {
  transform: rotateY(180deg);
}

.front, .back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border-radius: 10px;
}

.front {
  background: #ff7f50;
}

.back {
  background: #4caf50;
  transform: rotateY(180deg);
}

 

🔳 4. Animasi CSS 3D Cube (Berputar Otomatis)

1
2
3
4
5
6
.cube-container {
  perspective: 900px;
  width: 200px;
  height: 200px;
  margin: 60px auto;
}

.cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: spin 6s infinite linear;
}

.face {
  position: absolute;
  width: 200px;
  height: 200px;
  background: #4a90e2;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: #fff;
}

/* posisi kubus */
.front  { transform: translateZ(100px); }
.back   { transform: rotateY(180deg) translateZ(100px); }
.right  { transform: rotateY(90deg)  translateZ(100px); }
.left   { transform: rotateY(-90deg) translateZ(100px); }
.top    { transform: rotateX(90deg)  translateZ(100px); }
.bottom { transform: rotateX(-90deg) translateZ(100px); }

/* animasi */
@keyframes spin {
  0%   { transform: rotateX(0deg) rotateY(0deg); }
  100% { transform: rotateX(360deg) rotateY(360deg); }
}

 

🔥 5. Efek 3D Depth (Gerak Ikut Mouse)

3D Tilt
.tilt-card {
  width: 200px;
  height: 200px;
  background: linear-gradient(45deg, #6a11cb, #2575fc);
  border-radius: 15px;
  transition: transform .1s;
  transform-style: preserve-3d;
}
const card = document.querySelector(".tilt-card");

document.addEventListener("mousemove", (e) => {
  const x = (window.innerWidth / 2 - e.clientX) / 20;
  const y = (window.innerHeight / 2 - e.clientY) / 20;
  card.style.transform = `rotateY(${x}deg) rotateX(${y}deg)`;
});

 

✔️ Mau animasi CSS 3D model lain?

Saya bisa buat:

✨ 3D Loading
✨ 3D Text Animation
✨ 3D Carousel
✨ 3D Menu Hover
✨ 3D Logo Rotate
✨ 3D Scene + Lighting CSS

 

Cukup bilang "buatkan animasi X" dan saya siapkan kode lengkapnya.

Suka Artikel Ini? Tetap dapatkan Informasi dengan Berlanggana via email

Comments

You must be logged in to post a comment.

About Author

Pelukis Waktu: Kisah Penjaga Warisan