1. 布局
  2. top / right / bottom / left

布局

定位偏移

用于控制定位元素位置的工具类。

ClassStyles
inset-<number>
inset: calc(var(--spacing) * <number>);
-inset-<number>
inset: calc(var(--spacing) * -<number>);
inset-<fraction>
inset: calc(<fraction> * 100%);
-inset-<fraction>
inset: calc(<fraction> * -100%);
inset-px
inset: 1px;
-inset-px
inset: -1px;
inset-full
inset: 100%;
-inset-full
inset: -100%;
inset-auto
inset: auto;
inset-(<custom-property>)
inset: var(<custom-property>);

示例

基础示例

使用 top-<number>right-<number>bottom-<number>left-<number>inset-<number> 工具类(如 top-0bottom-4)来设置定位元素的水平或垂直位置:

01
02
03
04
05
06
07
08
09
<!-- 固定到左上角 --><div class="relative size-32 ...">  <div class="absolute top-0 left-0 size-16 ...">01</div></div><!-- 跨越顶部边缘 --><div class="relative size-32 ...">  <div class="absolute inset-x-0 top-0 h-16 ...">02</div></div><!-- 固定到右上角 --><div class="relative size-32 ...">  <div class="absolute top-0 right-0 size-16 ...">03</div></div><!-- 跨越左边缘 --><div class="relative size-32 ...">  <div class="absolute inset-y-0 left-0 w-16 ...">04</div></div><!-- 填充整个父元素 --><div class="relative size-32 ...">  <div class="absolute inset-0 ...">05</div></div><!-- 跨越右边缘 --><div class="relative size-32 ...">  <div class="absolute inset-y-0 right-0 w-16 ...">06</div></div><!-- 固定到左下角 --><div class="relative size-32 ...">  <div class="absolute bottom-0 left-0 size-16 ...">07</div></div><!-- 跨越底部边缘 --><div class="relative size-32 ...">  <div class="absolute inset-x-0 bottom-0 h-16 ...">08</div></div><!-- 固定到右下角 --><div class="relative size-32 ...">  <div class="absolute right-0 bottom-0 size-16 ...">09</div></div>

使用负值

要使用负的 top/right/bottom/left 值,在类名前加上破折号将其转换为负值:

<div class="relative size-32 ...">  <div class="absolute -top-4 -left-4 size-14 ..."></div></div>

使用自定义值

Use the top-[<value>] syntax to set the top / right / bottom / left based on a completely custom value:

<div class="top-[3px] ...">  <!-- ... --></div>

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

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

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

响应式设计

Prefix a top / right / bottom / left utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="top-0 md:inset-x-0 ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

自定义主题

The -<number> utilities are driven by the --spacing theme variable, which can be customized in your own theme:

@theme {  --spacing: 1px; }

Learn more about customizing the spacing scale in the theme variable documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy