rotate()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
CSS 的 rotate() 函数定义了一种将元素围绕一个定点(由transform-origin属性指定)旋转而不变形的转换。指定的角度定义了旋转的量度。若角度为正,则顺时针方向旋转,否则逆时针方向旋转。旋转 180° 也被称为点反射。
尝试一下
transform: rotate(0); transform: rotate(90deg); transform: rotate(-0.25turn); transform: rotate(3.142rad); <section id="default-example"> <img class="transition-all" id="example-element" src="/shared-assets/images/examples/firefox-logo.svg" width="200" /> </section> 元素旋转的固定点 - 如上所述 - 也称为变换原点。这默认为元素的中心,但你可以使用transform-origin属性设置自己的自定义变换原点。
语法
<angle> 指定了 rotate() 的旋转程度。参数为正时,顺时针旋转;参数为负时,逆时针旋转。180° 旋转称为点反演。
css
rotate(a) 值
| 笛卡尔坐标系 on ℝ2 | 齐次坐标系 on ℝℙ2 | 笛卡尔坐标系 on ℝ3 | 齐次坐标系 on ℝℙ3 |
|---|---|---|---|
[cos(a) sin(a) -sin(a) cos(a) 0 0] |
示例
>HTML
html
<div>Normal</div> <div class="rotated">Rotated</div> 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> |