rotate()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
CSS 的 rotate()
函数定义了一种将元素围绕一个定点(由transform-origin
属性指定)旋转而不变形的转换。指定的角度定义了旋转的量度。若角度为正,则顺时针方向旋转,否则逆时针方向旋转。旋转 180° 也被称为点反射。
尝试一下
transform: rotate(0);
transform: rotate(90deg);
transform: rotate(-0.25turn);
transform: rotate(3.142rad);
元素旋转的固定点 - 如上所述 - 也称为变换原点。这默认为元素的中心,但你可以使用transform-origin
属性设置自己的自定义变换原点。
语法
值
笛卡尔坐标系 on ℝ2 |
齐次坐标系 on ℝℙ2 | 笛卡尔坐标系 on ℝ3 | 齐次坐标系 on ℝℙ3 |
---|---|---|---|
[cos(a) sin(a) -sin(a) cos(a) 0 0] |
示例
HTML
html
Normal
Rotated
CSS
css
div {
width: 80px;
height: 80px;
background-color: skyblue;
}
.rotated {
transform: rotate(45deg); /* Equal to rotateZ(45deg) */
background-color: pink;
}
结果
规范
Specification |
---|
CSS Transforms Module Level 1 # funcdef-transform-rotate |