z-index

Các tiện ích để kiểm soát thứ tự xếp chồng của một phần tử.

ClassStyles
z-<number>
z-index: <number>;
z-auto
z-index: auto;
z-[<value>]
z-index: <value>;
z-(<custom-property>)
z-index: var(<custom-property>);

Ví dụ

Ví dụ cơ bản

Sử dụng các tiện ích z-<number> như z-10z-50 để kiểm soát thứ tự xếp chồng (hoặc định vị ba chiều) của một phần tử, bất kể thứ tự nó được hiển thị:

05
04
03
02
01
<div class="z-40 ...">05</div><div class="z-30 ...">04</div><div class="z-20 ...">03</div><div class="z-10 ...">02</div><div class="z-0 ...">01</div>

Sử dụng giá trị âm

Để sử dụng giá trị z-index âm, hãy thêm dấu gạch ngang trước tên class để chuyển đổi nó thành giá trị âm:

01
02
03
04
05
<div class="...">05</div><div class="...">04</div><div class="-z-10 ...">03</div><div class="...">02</div><div class="...">01</div>

Sử dụng giá trị tùy chỉnh

Use the z-[<value>] syntax to set the stack order based on a completely custom value:

<div class="z-[calc(var(--index)+1)] ...">  <!-- ... --></div>

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

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

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

Responsive design

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

<div class="z-0 md:z-50 ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

Copyright © 2025 Tailwind Labs Inc.·Chính sách thương hiệu