今天继续学习html空间转换
rotateX(angle)、rotateY(angle)、rotateZ(angle)分别用于绕 X 轴、Y 轴、Z 轴旋转元素,angle 表示旋转的角度,单位为度,正值表示顺时针旋转,负值表示逆时针旋转
代码示例:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style>.parent {perspective: 500px;}.box {width: 100px;height: 100px;background-color: green;transform-style: preserve-3d;transform: rotateX(45deg);}</style>
</head>
<body><div class="parent"><div class="box"></div></div>
</body>
</html>
scale3d(x, y, z)用于在 3D 空间中缩放元素,x、y、z 分别表示在水平、垂直和深度方向上的缩放比例
代码示例:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style>.parent {perspective: 500px;}.box {width: 100px;height: 100px;background-color: red;transform-style: preserve-3d;transform: scale3d(1.5, 1.2, 1);}</style>
</head>
<body><div class="parent"><div class="box"></div></div>
</body>
</html>