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

Z 指数

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

示例

🌐 Example

使用 z-index 工具将元素叠放在彼此之上。需要 position 值,而不能是 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 值用于像模态框和工具提示这样的覆盖组件。

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,
)