我刚迁移到Bootstrap 4,我的xs按钮似乎不再是extra small了!
查看Bootstrap 4中按钮的文档,我没有看到extra small按钮的选项?
有人能为我确认一下吗?
谢谢!
我刚迁移到Bootstrap 4,我的xs按钮似乎不再是extra small了!
查看Bootstrap 4中按钮的文档,我没有看到extra small按钮的选项?
有人能为我确认一下吗?
谢谢!
@rifton007在此问题的GitHub issue中发布了一个快速修复方法。将以下内容添加到您的CSS文件中:
.btn-group-xs > .btn, .btn-xs {
padding: .25rem .4rem;
font-size: .875rem;
line-height: .5;
border-radius: .2rem;
}
示例:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.btn-group-xs > .btn, .btn-xs {
padding: .25rem .4rem;
font-size: .875rem;
line-height: .5;
border-radius: .2rem;
}
</style>
<button class="btn btn-primary btn-xs">♡</button>
<button class="btn btn-primary btn-sm">♡</button>
<button class="btn btn-primary">♡</button>
<button class="btn btn-primary btn-lg">♡</button>
编辑:
之后在这个问题上,@deadmann 回复说他在旧的BS3文档中挖掘出以下代码:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.btn-group-xs > .btn, .btn-xs {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
</style>
<button class="btn btn-primary btn-xs">♡</button>
<button class="btn btn-primary btn-sm">♡</button>
<button class="btn btn-primary">♡</button>
<button class="btn btn-primary btn-lg">♡</button>
在 Bootstrap 4 中没有 btn-xs
这个类,你需要自己创建。在 scss/mixins/_buttons.scss
文件中可以找到名为 button-size
的 mixin,因此在 SCSS 代码中使用以下代码:
.btn-xs {
// line-height: ensure proper height of button next to extra small input
@include button-size($padding-y, $padding-x, $font-size, $line-height, $border-radius);
}
您需要定义自己的xs样式和变量,这个适合我最好,接近于Bootstrap 3的btn-xs大小:
Bootstrap 4 Alpha
$btn-padding-x-xs: .38rem !default;
$btn-padding-y-xs: .18rem !default;
.btn-xs {
@include button-size($btn-padding-y-xs, $btn-padding-x-xs, $font-size-sm, $btn-border-radius-sm);
}
Bootstrap 4 Beta 2
$btn-padding-x-xs: .20rem !default;
$btn-padding-y-xs: .12rem !default;
$input-btn-line-height-xs: 1.1 !default;
.btn.btn-xs {
// line-height: ensure proper height of button next to small input
@include button-size($btn-padding-y-xs, $btn-padding-x-xs, $font-size-sm, $input-btn-line-height-xs, $btn-border-radius-sm);
}
$line-height
参数。现在使用:@include button-size($btn-padding-y-xs, $btn-padding-x-xs, $font-size-sm, $input-btn-line-height-sm, $btn-border-radius-sm);
- voidstatebutton
{
margin-top: 10px;
margin-left: 10px;
}
.btn-xs
{
padding: 1px 5px !important;
font-size: 12px !important;
line-height: 1.5 !important;
border-radius: 3px !important;
}
<link rel="stylesheet" href="https://v4-alpha.getbootstrap.com/dist/css/bootstrap.min.css">
<button class="btn btn-primary btn-xs">This is Small Button</button>
在 Bootstrap 4 中,已经不再提供额外小号按钮的选项。现在只有三种尺寸可用:大号、正常和小号。
.btn-xs {
@include button-size($btn-padding-y-xs, $btn-padding-x-xs, $font-size-xs, $border-radius);
}