示例
¥Example
使用带有链接列表项的有序或无序列表来创建最小样式的面包屑。使用我们的工具根据需要添加其他样式。
¥Use an ordered or unordered list with linked list items to create a minimally styled breadcrumb. Use our utilities to add additional styles as desired.
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page">Home</li>
</ol>
</nav>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#">Library</a></li>
<li class="breadcrumb-item active" aria-current="page">Data</li>
</ol>
</nav>
分隔线
¥Dividers
分隔符通过 ::before
和 content
自动添加到 CSS 中。可以通过修改本地 CSS 自定义属性 --bs-breadcrumb-divider
或通过 $breadcrumb-divider
Sass 变量以及 $breadcrumb-divider-flipped
(如果需要)对其 RTL 对应项进行更改。我们默认使用 Sass 变量,该变量被设置为自定义属性的后备。这样,你就可以获得一个全局分隔符,你可以随时覆盖该分隔符,而无需重新编译 CSS。
¥Dividers are automatically added in CSS through ::before
and content
. They can be changed by modifying a local CSS custom property --bs-breadcrumb-divider
, or through the $breadcrumb-divider
Sass variable — and $breadcrumb-divider-flipped
for its RTL counterpart, if needed. We default to our Sass variable, which is set as a fallback to the custom property. This way, you get a global divider that you can override without recompiling CSS at any time.
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
通过 Sass 修改时,需要使用 quote 函数来生成字符串周围的引号。例如,使用 >
作为分隔符,你可以这样使用:
¥When modifying via Sass, the quote function is required to generate the quotes around a string. For example, using >
as the divider, you can use this:
$breadcrumb-divider: quote(">");
还可以使用嵌入的 SVG 图标。通过我们的 CSS 自定义属性应用它,或使用 Sass 变量。
¥It’s also possible to use an embedded SVG icon. Apply it via our CSS custom property, or use the Sass variable.
<
, >
and #
, must be URL-encoded or escaped. We do this with the $breadcrumb-divider
variable using our escape-svg()
Sass function. When customizing the CSS variable, you must handle this yourself. Read Kevin Weber’s explanations on CodePen for more info.
<nav style="--bs-breadcrumb-divider: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='%236c757d'/%3E%3C/svg%3E");" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
$breadcrumb-divider: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8'><path d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='#{$breadcrumb-divider-color}'/></svg>");
你还可以删除分隔符设置 --bs-breadcrumb-divider: '';
(CSS 自定义属性中的空字符串算作一个值),或将 Sass 变量设置为 $breadcrumb-divider: none;
。
¥You can also remove the divider setting --bs-breadcrumb-divider: '';
(empty strings in CSS custom properties counts as a value), or setting the Sass variable to $breadcrumb-divider: none;
.
<nav style="--bs-breadcrumb-divider: '';" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
$breadcrumb-divider: none;
无障碍
¥Accessibility
由于面包屑提供导航,因此最好添加有意义的标签(例如 aria-label="breadcrumb"
)来描述 <nav>
元素中提供的导航类型,并将 aria-current="page"
应用于集合的最后一项以指示它代表当前页面。
¥Since breadcrumbs provide a navigation, it’s a good idea to add a meaningful label such as aria-label="breadcrumb"
to describe the type of navigation provided in the <nav>
element, as well as applying an aria-current="page"
to the last item of the set to indicate that it represents the current page.
有关详细信息,请参阅 ARIA 创作实践指南 面包屑模式。
¥For more information, see the ARIA Authoring Practices Guide breadcrumb pattern.
CSS
变量
¥Variables
Added in v5.2.0作为 Bootstrap 不断发展的 CSS 变量方法的一部分,面包屑现在使用 .breadcrumb
上的本地 CSS 变量来增强实时自定义。CSS 变量的值是通过 Sass 设置的,因此仍然支持 Sass 自定义。
¥As part of Bootstrap’s evolving CSS variables approach, breadcrumbs now use local CSS variables on .breadcrumb
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
--#{$prefix}breadcrumb-padding-x: #{$breadcrumb-padding-x};
--#{$prefix}breadcrumb-padding-y: #{$breadcrumb-padding-y};
--#{$prefix}breadcrumb-margin-bottom: #{$breadcrumb-margin-bottom};
@include rfs($breadcrumb-font-size, --#{$prefix}breadcrumb-font-size);
--#{$prefix}breadcrumb-bg: #{$breadcrumb-bg};
--#{$prefix}breadcrumb-border-radius: #{$breadcrumb-border-radius};
--#{$prefix}breadcrumb-divider-color: #{$breadcrumb-divider-color};
--#{$prefix}breadcrumb-item-padding-x: #{$breadcrumb-item-padding-x};
--#{$prefix}breadcrumb-item-active-color: #{$breadcrumb-active-color};
Sass 变量
¥Sass variables
$breadcrumb-font-size: null;
$breadcrumb-padding-y: 0;
$breadcrumb-padding-x: 0;
$breadcrumb-item-padding-x: .5rem;
$breadcrumb-margin-bottom: 1rem;
$breadcrumb-bg: null;
$breadcrumb-divider-color: var(--#{$prefix}secondary-color);
$breadcrumb-active-color: var(--#{$prefix}secondary-color);
$breadcrumb-divider: quote("/");
$breadcrumb-divider-flipped: $breadcrumb-divider;
$breadcrumb-border-radius: null;