Skip to content

Transforms

<div class="rotate-45">หมุน 45°</div>
<div class="rotate-90">หมุน 90°</div>
<div class="rotate-180">หมุน 180°</div>
<div class="-rotate-45">หมุน -45°</div>
<div class="hover:rotate-180 transition duration-500">Rotate on hover</div>
ClassRotation
rotate-00deg
rotate-11deg
rotate-22deg
rotate-33deg
rotate-66deg
rotate-1212deg
rotate-4545deg
rotate-9090deg
rotate-180180deg
-rotate-45-45deg

<div class="scale-50">50% size</div>
<div class="scale-100">100% (normal)</div>
<div class="scale-110">10% larger</div>
<div class="scale-150">50% larger</div>
<div class="hover:scale-105 transition">Scale on hover</div>
<div class="scale-x-150">กว้างขึ้น 50%</div>
<div class="scale-y-50">สูงลด 50%</div>

<div class="translate-x-4">Move right 1rem</div>
<div class="translate-y-2">Move down 0.5rem</div>
<div class="-translate-x-4">Move left 1rem</div>
<div class="translate-x-1/2">Move right 50%</div>
<div class="hover:-translate-y-1 transition">Move up on hover</div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
Perfect center
</div>

<div class="skew-x-12">เอียงแนวนอน</div>
<div class="skew-y-6">เอียงแนวตั้ง</div>
<div class="-skew-x-6">เอียงแนวนอนกลับ</div>
ClassEffect
skew-x-00deg
skew-x-11deg
skew-x-22deg
skew-x-33deg
skew-x-66deg
skew-x-1212deg

กำหนดจุดศูนย์กลางของ transform:

<div class="origin-center rotate-45">หมุนจากตรงกลาง (default)</div>
<div class="origin-top-left rotate-45">หมุนจากมุมซ้ายบน</div>
<div class="origin-bottom rotate-45">หมุนจากด้านล่าง</div>
ClassOrigin
origin-centercenter
origin-toptop center
origin-bottombottom center
origin-leftleft center
origin-rightright center
origin-top-lefttop left
origin-top-righttop right
origin-bottom-leftbottom left
origin-bottom-rightbottom right

<div
class="hover:scale-105 hover:rotate-3 hover:-translate-y-1
transition-transform duration-300 ease-out"
>
Combined transforms on hover
</div>

ตัวอย่างการใช้งาน

Section titled “ตัวอย่างการใช้งาน”
<div class="group">
<div
class="transition-transform duration-300
group-hover:scale-105 group-hover:rotate-1"
>
<img src="..." class="rounded-lg" />
</div>
</div>
<button class="group">
<svg class="w-5 h-5 transition-transform group-hover:rotate-12">...</svg>
Settings
</button>

กำหนดระยะมองสำหรับ 3D effects:

<div class="perspective-500">
<div class="rotate-y-45">3D rotated element</div>
</div>
<div class="perspective-1000">
<div class="rotate-x-12">Less dramatic 3D</div>
</div>
ClassValue
perspective-nonenone
perspective-250250px
perspective-500500px
perspective-750750px
perspective-10001000px
<!-- Rotate along X axis -->
<div class="rotate-x-12">Tilt forward/back</div>
<div class="rotate-x-45">More tilt</div>
<div class="-rotate-x-12">Tilt backward</div>
<!-- Rotate along Y axis -->
<div class="rotate-y-12">Rotate left/right</div>
<div class="rotate-y-180">Flip horizontally</div>
<div class="transform-3d">
<!-- Children maintain 3D space -->
<div class="rotate-y-45">Stays 3D</div>
</div>
<!-- ซ่อนด้านหลังเมื่อหมุน -->
<div class="backface-hidden rotate-y-180">Hidden when flipped</div>
<div class="backface-visible rotate-y-180">Always visible</div>

<div class="group perspective-1000 w-64 h-40">
<div
class="relative w-full h-full transition-transform duration-500
transform-3d group-hover:rotate-y-180"
>
<!-- Front -->
<div
class="absolute inset-0 backface-hidden bg-blue-500
rounded-lg flex items-center justify-center text-white"
>
<p class="text-xl font-bold">Front Side</p>
</div>
<!-- Back -->
<div
class="absolute inset-0 backface-hidden rotate-y-180 bg-purple-500
rounded-lg flex items-center justify-center text-white"
>
<p class="text-xl font-bold">Back Side</p>
</div>
</div>
</div>

Do ✅Don’t ❌
ใช้ transition กับ transformsTransform โดยไม่มี transition
ใช้ will-change-transform สำหรับ heavy animationsใส่ will-change ทุกที่
ใช้ 3D transforms เมื่อจำเป็นใช้ 3D สำหรับ 2D effects
ใช้ perspective กับ parentใส่ perspective บน element เดียวกัน