1. 变换
  2. 旋转

变换

旋转

用于旋转元素的工具类。

ClassStyles
rotate-none
rotate: none;
rotate-<number>
rotate: <number>deg;
-rotate-<number>
rotate: calc(<number>deg * -1);
rotate-(<custom-property>)
rotate: var(<custom-property>);
rotate-[<value>]
rotate: <value>;
rotate-x-<number>
transform: rotateX(<number>deg) var(--tw-rotate-y);
-rotate-x-<number>
transform: rotateX(-<number>deg) var(--tw-rotate-y);
rotate-x-(<custom-property>)
transform: rotateX(var(<custom-property>)) var(--tw-rotate-y);
rotate-x-[<value>]
transform: rotateX(<value>) var(--tw-rotate-y);
rotate-y-<number>
transform: var(--tw-rotate-x) rotateY(<number>deg);

示例

基本示例

使用 rotate-<number> 工具类,如 rotate-45rotate-90,以度为单位旋转元素:

rotate-45

rotate-90

rotate-210

<img class="rotate-45 ..." src="/img/mountains.jpg" />
<img class="rotate-90 ..." src="/img/mountains.jpg" />
<img class="rotate-210 ..." src="/img/mountains.jpg" />

使用负值

使用 -rotate-<number> 工具类,如 -rotate-45-rotate-90,以度为单位逆时针旋转元素:

-rotate-45

-rotate-90

-rotate-210

<img class="-rotate-45 ..." src="/img/mountains.jpg" />
<img class="-rotate-90 ..." src="/img/mountains.jpg" />
<img class="-rotate-210 ..." src="/img/mountains.jpg" />

在 3D 空间中旋转

使用 rotate-x-<number>rotate-y-<number>rotate-z-<number> 工具类,如 rotate-x-50-rotate-y-30rotate-z-45 一起旋转元素,在 3D 空间中:

rotate-x-50

rotate-z-45

rotate-x-15

-rotate-y-30

rotate-y-25

rotate-z-30

<img class="rotate-x-50 rotate-z-45 ..." src="/img/mountains.jpg" />
<img class="rotate-x-15 -rotate-y-30 ..." src="/img/mountains.jpg" />
<img class="rotate-y-25 rotate-z-30 ..." src="/img/mountains.jpg" />

使用自定义值

Use the rotate-[<value>] syntax to set the rotation based on a completely custom value:

<img class="rotate-[3.142rad] ..." src="/img/mountains.jpg" />

For CSS variables, you can also use the rotate-(<custom-property>) syntax:

<img class="rotate-(--my-rotation) ..." src="/img/mountains.jpg" />

This is just a shorthand for rotate-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix a rotate utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<img class="rotate-45 md:rotate-60 ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.