Layout
用于控制元素堆叠顺序的工具类。
| Class | Styles |
|---|---|
z-<number> | z-index: <number>; |
z-auto | z-index: auto; |
z-[<value>] | z-index: <value>; |
z-(<custom-property>) | z-index: var(<custom-property>); |
使用 z-<number> 工具类(如 z-10 和 z-50)来控制元素的堆叠顺序(或三维定位),而不受其显示顺序的影响:
<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>要使用负的 z-index 值,在类名前加上破折号将其转换为负值:
<div class="...">05</div><div class="...">04</div><div class="-z-10 ...">03</div><div class="...">02</div><div class="...">01</div>Use the z-[<value>] syntax to set the 堆叠顺序 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.
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.