确实缺少 nav-justify 类。暂时可以根据 TB3 的代码自行添加:
SCSS 代码
// Justified button groups
// ----------------------
.btn-group-justified {
display: table;
width: 100%;
table-layout: fixed;
border-collapse: separate;
.btn,
.btn-group {
float: none;
display: table-cell;
width: 1%;
.btn {
width: 100%;
}
.dropdown-menu {
left: auto;
}
}
}
编译的 CSS 代码
.btn-group-justified {
display: table;
width: 100%;
table-layout: fixed;
border-collapse: separate; }
.btn-group-justified .btn,
.btn-group-justified .btn-group {
float: none;
display: table-cell;
width: 1%; }
.btn-group-justified .btn .btn,
.btn-group-justified .btn-group .btn {
width: 100%; }
.btn-group-justified .btn .dropdown-menu,
.btn-group-justified .btn-group .dropdown-menu {
left: auto; }
HTML
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group">
<a class="btn btn-primary" href="#" role="button">Left</a>
<a class="btn btn-primary" href="#" role="button">Middle</a>
<a class="btn btn-primary" href="#" role="button">Right</a>
</div>
上面的 HTML 代码现在将如下图所示:
处理边框
- 由于用于对齐按钮的特定 HTML 和 CSS(即
display: table-cell),它们之间的边框加倍。在常规按钮组中,margin-left: -1px 用于堆叠边框而不是移除它们。但是,margin 不适用于 display: table-cell。因此,根据您对 Bootstrap 的自定义,您可能希望移除或重新着色边框。
充当按钮的链接
- 如果
<a> 元素用作按钮 - 触发页面内功能,而不是导航到当前页面中的另一个文档或部分 - 它们也应该被赋予适当的 role="button"。
下拉菜单
对下拉按钮使用以下 HTML 代码:
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group with nested dropdown">
<a class="btn btn-secondary" href="#" role="button">Left</a>
<a class="btn btn-secondary" href="#" role="button">Middle</a>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Action
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</div>
</div>
带有下拉按钮的对齐按钮组应如下图所示:
带有<button> 元素
- 要使用带有
<button> 元素的对齐按钮组,您必须将每个按钮包装在一个按钮组中。大多数浏览器不会正确地将我们的 CSS 应用到 <button> 元素,但由于我们支持按钮下拉菜单,我们可以解决这个问题。
HTML
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group">
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary">Left</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary">Middle</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary">Right</button>
</div>
</div>
上面用于对齐带有<button>元素的按钮组的HTML代码应该如下图所示: