Skip to main content Skip to docs navigation
Added in v5.3

Z 指数

使用我们的底层 z-index 工具快速更改元素或组件的堆栈级别。

示例

¥Example

使用 z-index 工具将元素堆叠在一起。需要除 static 之外的 position 值,可以使用自定义样式或使用我们的 位置实用程序 进行设置。

¥Use z-index utilities to stack elements on top of one another. Requires a position value other than static, which can be set with custom styles or using our position utilities.

我们称这些为“底层”z-index 实用程序,因为它们的默认值为 -13,我们用它们来布局重叠组件。高级 z-index 值用于覆盖组件,例如模态窗口和工具提示。

¥We call these “low-level” z-index utilities because of their default values of -1 through 3, which we use for the layout of overlapping components. High-level z-index values are used for overlay components like modals and tooltips.

z-3
z-2
z-1
z-0
z-n1
html
<div class="z-3 position-absolute p-5 rounded-3"><span>z-3</span></div>
<div class="z-2 position-absolute p-5 rounded-3"><span>z-2</span></div>
<div class="z-1 position-absolute p-5 rounded-3"><span>z-1</span></div>
<div class="z-0 position-absolute p-5 rounded-3"><span>z-0</span></div>
<div class="z-n1 position-absolute p-5 rounded-3"><span>z-n1</span></div>

叠加层

¥Overlays

Bootstrap 的叠加组件(下拉菜单、模态框、画布外显示、弹出窗口、提示框和工具提示)都有各自的 z-index 值,以确保界面中相互竞争的“层”能够提供良好的用户体验。

¥Bootstrap overlay components—dropdown, modal, offcanvas, popover, toast, and tooltip—all have their own z-index values to ensure a usable experience with competing “layers” of an interface.

z-index 布局页面 中了解它们。

¥Read about them in the z-index layout page.

组件方法

¥Component approach

在某些组件上,我们使用底层 z-index 值来管理彼此重叠的重复元素(例如按钮组中的按钮或列表组中的项目)。

¥On some components, we use our low-level z-index values to manage repeating elements that overlap one another (like buttons in a button group or items in a list group).

了解我们的 z-index 方法

¥Learn about our z-index approach.

CSS

Sass 映射

¥Sass maps

自定义此 Sass 映射以更改可用值和生成的工具。

¥Customize this Sass map to change the available values and generated utilities.

$zindex-levels: (
  n1: -1,
  0: 0,
  1: 1,
  2: 2,
  3: 3
);

Sass 工具 API

¥Sass utilities API

头寸工具在 scss/_utilities.scss 中的工具 API 中声明。了解如何使用实用程序 API。

¥Position utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.

"z-index": (
  property: z-index,
  class: z,
  values: $zindex-levels,
)