btn-xs不再是bootstrap 4中的有效选项吗?

Dra*_*gan 47 twitter-bootstrap twitter-bootstrap-4 bootstrap-4

我刚刚迁移到bootstrap 4,我的xs按钮似乎不再特别小!

查看bootstrap 4中按钮文档,我没有看到额外的小按钮选项?

谁能为我证实这一点?

谢谢!

alo*_*ica 43

如果它可以帮助某人,@ rifton007快速解决了问题.在您的css文件中添加:

.btn-group-xs > .btn, .btn-xs {
  padding: .25rem .4rem;
  font-size: .875rem;
  line-height: .5;
  border-radius: .2rem;
}
Run Code Online (Sandbox Code Playgroud)

演示:

<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>
Run Code Online (Sandbox Code Playgroud)

资源

  • ** + 1 **引用了原始Source-Link并给予** Rifton007 **适当的信用。在Source-Link中,“ Squadwuschel **”提出了一个很好的观点,即我们不是每个人都在编写响应式移动应用程序,以及有时您只是想在网格中滑动一个按钮以获取不会过度扩展每个桌面的桌面体验它在其中。 (3认同)

Bas*_*sen 12

是的,btn-xs在Bootstrap 4中没有,你必须自己创建这个类.在scss/mixins/_buttons.scss你会发现称为混入button-size所以你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);
}
Run Code Online (Sandbox Code Playgroud)

  • 你能提供CSS吗? (3认同)

squ*_*hel 10

你需要定义你自己的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);
}
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)


小智 7

我从旧版本的 Bootstrap 中提取了 CSS。您可以在自定义样式表中使用下面提到的 CSS 样式。在名为 btn-xs 的类的帮助下,您可以使用旧的按钮样式。

祝你好运。

button
{
  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;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)