<angle>

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

<angle> CSS 数据类型表示以度、梯度、弧度或圈数表示的角度值。它用于例如<gradient>和某些transform函数。

试一试

transform: rotate(45deg);
transform: rotate(3.1416rad);
transform: rotate(-50grad);
transform: rotate(1.75turn);
<section class="default-example" id="default-example">
  <div class="transition-all" id="example-element">
    This box can rotate to different angles.
  </div>
</section>
#example-element {
  background-color: #0118f3;
  padding: 0.75em;
  width: 180px;
  height: 120px;
  color: white;
}

语法

<angle>数据类型由一个<number>后跟以下列出的其中一个单位组成。与所有尺寸一样,单位字面量和数字之间没有空格。在数字0之后,角度单位是可选的。

可选地,它前面可以有一个+-号。正数表示顺时针角度,而负数表示逆时针角度。对于给定单位的静态属性,任何角度都可以用各种等效值表示。例如,90deg等于-270deg1turn等于4turn。对于动态属性,例如应用animationtransition时,效果将仍然不同。

单位

deg

表示以为单位的角度。一个整圆是360deg。示例:0deg90deg14.23deg

grad

表示以梯度为单位的角度。一个整圆是400grad。示例:0grad100grad38.8grad

rad

表示以弧度为单位的角度。一个整圆是2π弧度,约等于6.2832rad1rad是180/π度。示例:0rad1.0708rad6.2832rad

turn

表示以圈数为单位的角度。一个整圆是1turn。示例:0turn0.25turn1.2turn

示例

设置顺时针直角

A diagram showing a clockwise 90-degree rotation along a circle by moving from the topmost point to the rightmost point. 90deg = 100grad = 0.25turn ≈ 1.5708rad

设置平角

A diagram showing a clockwise 180-degree rotation along a circle by moving from the topmost point to the bottommost point. 180deg = 200grad = 0.5turn ≈ 3.1416rad

设置逆时针直角

A diagram showing a counterclockwise 90-degree rotation along a circle by moving from the topmost point to the leftmost point. -90deg = -100grad = -0.25turn ≈ -1.5708rad

设置零角

A diagram showing a 0-degree rotation. There is no movement. 0 = 0deg = 0grad = 0turn = 0rad

规范

规范
CSS 值和单位模块第 4 级
# 角度

浏览器兼容性

另见