การแปลง CSS 3D
การแปลง CSS 3D
CSS ยังสนับสนุนการแปลง 3D
วางเมาส์เหนือองค์ประกอบด้านล่างเพื่อดูความแตกต่างระหว่างการแปลง 2D และ 3D:
2D หมุน
3D หมุน
ในบทนี้ คุณจะได้เรียนรู้เกี่ยวกับคุณสมบัติ CSS ต่อไปนี้:
transform
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
transform | 36.0 |
10.0 |
16.0 |
9.0 |
23.0 |
วิธีการแปลง CSS 3D
ด้วยคุณสมบัติ CSS transform
คุณสามารถใช้วิธีการแปลง 3 มิติต่อไปนี้:
rotateX()
rotateY()
rotateZ()
วิธีrotationX()
วิธี การrotateX()
หมุนองค์ประกอบรอบแกน X ในระดับที่กำหนด:
ตัวอย่าง
#myDiv
{
transform: rotateX(150deg);
}
วิธีการหมุนY()
วิธี การrotateY()
หมุนองค์ประกอบรอบแกน Y ในระดับที่กำหนด:
ตัวอย่าง
#myDiv
{
transform: rotateY(150deg);
}
หมุนZ() Method
วิธี การrotateZ()
หมุนองค์ประกอบรอบแกน Z ในระดับที่กำหนด:
ตัวอย่าง
#myDiv
{
transform: rotateZ(90deg);
}
คุณสมบัติการแปลง CSS
ตารางต่อไปนี้แสดงรายการคุณสมบัติการแปลง 3D ทั้งหมด:
Property | Description |
---|---|
transform | Applies a 2D or 3D transformation to an element |
transform-origin | Allows you to change the position on transformed elements |
transform-style | Specifies how nested elements are rendered in 3D space |
perspective | Specifies the perspective on how 3D elements are viewed |
perspective-origin | Specifies the bottom position of 3D elements |
backface-visibility | Defines whether or not an element should be visible when not facing the screen |
วิธีการแปลง CSS 3D
Function | Description |
---|---|
matrix3d (n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n) |
Defines a 3D transformation, using a 4x4 matrix of 16 values |
translate3d(x,y,z) | Defines a 3D translation |
translateX(x) | Defines a 3D translation, using only the value for the X-axis |
translateY(y) | Defines a 3D translation, using only the value for the Y-axis |
translateZ(z) | Defines a 3D translation, using only the value for the Z-axis |
scale3d(x,y,z) | Defines a 3D scale transformation |
scaleX(x) | Defines a 3D scale transformation by giving a value for the X-axis |
scaleY(y) | Defines a 3D scale transformation by giving a value for the Y-axis |
scaleZ(z) | Defines a 3D scale transformation by giving a value for the Z-axis |
rotate3d(x,y,z,angle) | Defines a 3D rotation |
rotateX(angle) | Defines a 3D rotation along the X-axis |
rotateY(angle) | Defines a 3D rotation along the Y-axis |
rotateZ(angle) | Defines a 3D rotation along the Z-axis |
perspective(n) | Defines a perspective view for a 3D transformed element |