Skip to main content Skip to docs navigation

Z 指数

虽然 z 索引不是 Bootstrap 网格系统的一部分,但它在我们的组件如何相互叠加和交互方面发挥着重要作用。

一些 Bootstrap 组件利用 z-index,CSS 属性通过提供第三个轴来排列内容来帮助控制布局。我们在 Bootstrap 中使用默认的 z 索引比例,该比例旨在正确分层导航、工具提示和弹出窗口、模式等。

¥Several Bootstrap components utilize z-index, the CSS property that helps control layout by providing a third axis to arrange content. We utilize a default z-index scale in Bootstrap that’s been designed to properly layer navigation, tooltips and popovers, modals, and more.

这些较高的值从任意数字开始,足够高且具体,可以理想地避免冲突。我们的分层组件需要一套标准的工具提示、弹出窗口、导航栏、下拉菜单、模式,这样我们的行为就可以相当一致。我们没有理由不能使用 100+ 或 500+。

¥These higher values start at an arbitrary number, high and specific enough to ideally avoid conflicts. We need a standard set of these across our layered components—tooltips, popovers, navbars, dropdowns, modals—so we can be reasonably consistent in the behaviors. There’s no reason we couldn’t have used 100+ or 500+.

我们不鼓励定制这些单独的值;如果你更改其中一项,你可能需要更改全部。

¥We don’t encourage customization of these individual values; should you change one, you likely need to change them all.

$zindex-dropdown:                   1000;
$zindex-sticky:                     1020;
$zindex-fixed:                      1030;
$zindex-offcanvas-backdrop:         1040;
$zindex-offcanvas:                  1045;
$zindex-modal-backdrop:             1050;
$zindex-modal:                      1055;
$zindex-popover:                    1070;
$zindex-tooltip:                    1080;
$zindex-toast:                      1090;

为了处理组件内的重叠边框(例如,输入组中的按钮和输入),我们使用 123 的低个位数 z-index 值来表示默认、悬停和活动状态。在悬停/焦点/活动时,我们将具有较高 z-index 值的特定元素带到最前面,以显示其在同级元素上的边框。

¥To handle overlapping borders within components (e.g., buttons and inputs in input groups), we use low single digit z-index values of 1, 2, and 3 for default, hover, and active states. On hover/focus/active, we bring a particular element to the forefront with a higher z-index value to show their border over the sibling elements.