1. 变换
  2. 透视原点

变换

透视原点

控制元素在三维空间中的透视原点的工具。

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

示例

基本示例

使用 透视原点-顶部透视原点-底部左侧 等工具来控制透视消失点的位置:

透视原点-顶部左侧

1
2
3
4
5
6

透视原点-底部右侧

1
2
3
4
5
6
<div class="size-20 perspective-near perspective-origin-top-left ...">
<div class="translate-z-12 rotate-x-0 bg-sky-300/75 ...">1</div>
<div class="-translate-z-12 rotate-y-18 bg-sky-300/75 ...">2</div>
<div class="translate-x-12 rotate-y-90 bg-sky-300/75 ...">3</div>
<div class="-translate-x-12 -rotate-y-90 bg-sky-300/75 ...">4</div>
<div class="-translate-y-12 rotate-x-90 bg-sky-300/75 ...">5</div>
<div class="translate-y-12 -rotate-x-90 bg-sky-300/75 ...">6</div>
</div>
<div class="size-20 perspective-near perspective-origin-bottom-right …">
<div class="translate-z-12 rotate-x-0 bg-sky-300/75 ...">1</div>
<div class="-translate-z-12 rotate-y-18 bg-sky-300/75 ...">2</div>
<div class="translate-x-12 rotate-y-90 bg-sky-300/75 ...">3</div>
<div class="-translate-x-12 -rotate-y-90 bg-sky-300/75 ...">4</div>
<div class="-translate-y-12 rotate-x-90 bg-sky-300/75 ...">5</div>
<div class="translate-y-12 -rotate-x-90 bg-sky-300/75 ...">6</div>
</div>

使用自定义值

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

<div class="perspective-origin-[200%_150%] ...">
<!-- ... -->
</div>

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

<div class="perspective-origin-(--my-perspective-origin) ...">
<!-- ... -->
</div>

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

响应式设计

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

<div class="perspective-origin-center md:perspective-origin-bottom-left ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.