布局
用于控制元素堆叠顺序的工具。
¥Basic usage
¥Setting the z-index
使用 z-*
工具来控制元素的堆叠顺序(或三维定位),无论其显示顺序如何。
¥Use the z-*
utilities to control the stack order (or three-dimensional positioning) of an element, regardless of order it has been displayed.
<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>
¥Using negative values
要使用负 z-index 值,请在类名前加上破折号以将其转换为负值。
¥To use a negative z-index value, prefix the class name with a dash to convert it to a negative value.
<div class="-z-50">
<!-- ... -->
</div>
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:z-50
to only apply the z-50
utility on hover.
<div class="z-0 hover:z-50">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:z-50
to apply the z-50
utility at only medium screen sizes and above.
<div class="z-0 md:z-50">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
¥Using custom values
¥Customizing your theme
默认情况下,Tailwind 提供六个数字 z-index
工具和一个 auto
工具。你可以通过编辑 tailwind.config.js
文件中的 theme.zIndex
或 theme.extend.zIndex
来自定义这些值。
¥By default, Tailwind provides six numeric z-index
utilities and an auto
utility. You can customize these values by editing theme.zIndex
or theme.extend.zIndex
in your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
zIndex: {
'100': '100',
}
}
}
}
在 主题定制 文档中了解有关自定义默认主题的更多信息。
¥Learn more about customizing the default theme in the theme customization documentation.
¥Arbitrary values
If you need to use a one-off z-index
value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<div class="z-[100]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.