1. 变换
  2. 变换原点

变换

transform-origin

用于指定元素变换的原点的工具类。

ClassStyles
origin-center
transform-origin: center;
origin-top
transform-origin: top;
origin-top-right
transform-origin: top right;
origin-right
transform-origin: right;
origin-bottom-right
transform-origin: bottom right;
origin-bottom
transform-origin: bottom;
origin-bottom-left
transform-origin: bottom left;
origin-left
transform-origin: left;
origin-top-left
transform-origin: top left;
origin-(<custom-property>)
transform-origin: var(<custom-property>);
origin-[<value>]
transform-origin: <value>;

示例

基本示例

使用 origin-toporigin-bottom-left 等工具类来设置元素的变换原点:

origin-center

origin-top-left

origin-bottom

<img class="origin-center rotate-45 ..." src="/img/mountains.jpg" />
<img class="origin-top-left rotate-12 ..." src="/img/mountains.jpg" />
<img class="origin-bottom -rotate-12 ..." src="/img/mountains.jpg" />

使用自定义值

Use the origin-[<value>] syntax to set the 变换原点 based on a completely custom value:

<img class="origin-[33%_75%] ..." src="/img/mountains.jpg" />

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

<img class="origin-(--my-transform-origin) ..." src="/img/mountains.jpg" />

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

响应式设计

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

<img class="origin-center md:origin-top ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.