CSS - boostrap btn-group-justified with buttons between

时间:2017-02-21 09:59:56

标签: html css twitter-bootstrap

在下面的示例中,您可以看到按钮几乎无法与彼此区分,因此想要在按钮之间使用一些间距,如btn-toolbar。我不能使用它,但因为按钮将非常小,并没有填满整个div

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="btn-group btn-group-justified" role="group">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">Yes</button>
    </div>
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">No</button>
    </div>
</div>

我希望间距是这样的:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="btn-toolbar" role="group">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">Yes</button>
    </div>
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">No</button>
    </div>
</div>

3 个答案:

答案 0 :(得分:1)

您可以使用自举网格系统。

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class=" btn-group btn-group-justified" role="group">
<div class=" col-xs-5">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">Yes</button>
        </div>
    </div>
    <div class=" col-xs-5">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">No</button>
        </div>
        </div>
    </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

这是另一个解决方案。由于btn-group只围绕组的左右边缘,因此您要从.btn-group中删除<div class=" btn-group btn-group-justified" role="group">,然后将填充设置为类.btn-group的内部div

如您所愿,您可以为此.btn-group定义更高的特异性,以防止外部传播风格。

&#13;
&#13;
.btn-group {
  padding-left: 2px;
  padding-right: 2px;
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="btn-group-justified" role="group">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">Yes</button>
    </div>
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary">No</button>
    </div>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

你在找下面的东西吗?

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
   <div class="col-xs-6">
         <button type="button" class="btn btn-primary btn-lg btn-block">Yes</button>
   </div>
   <div class="col-xs-6">
         <button type="button" class="btn btn-default btn-lg btn-block">No</button>
    </div>
</div>
&#13;
&#13;
&#13;

希望这有帮助。