引导模态体上的行没有间隙?

时间:2015-10-06 09:28:49

标签: twitter-bootstrap bootstrap-modal

在我的bootstrap模式中,我有两行,但它们都在行之间没有间距地聚集。

问题:为什么bootstrap模态体上的行之间没有间隙,哪种解决方案最好?

代码预览Click Here

完整预览{​​{3}}

Click Here

HTML

<div class="container">
<hr>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Click To Open Modal
</button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
    <div class="row">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <a href="" id="button-parent" class="btn btn-default">Parent Folder</a> 
    <a href="" id="button-refresh" class="btn btn-default">Refresh Page</a>
    <button type="button" id="button-upload" class="btn btn-primary">Upload</button>
    <button type="button" id="button-folder" class="btn btn-default">Create Folder</button>
    <button type="button" id="button-delete" class="btn btn-danger">Delete</button>
    </div>
    </div>

    <div class="row">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="input-group">
    <input type="text" name="search" value="" placeholder="" class="form-control">
    <span class="input-group-btn">
    <button type="button" data-toggle="tooltip" title="<?php echo $button_search; ?>" id="button-search" class="btn btn-primary"><i class="fa fa-search"></i></button>
    </span>
    </div>
    </div>
    </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:3)

每当你在bootstrap中使用form-elements时,建议你将那个特定元素放在一个form-group类中 - 这样,每个元素下面都有一个15px的margin-bottom。

  

As per Bootstrap's form example:在.form-group中包装标签和控件以获得最佳间距。

.inline-group {
  display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <hr>
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Click To Open Modal
  </button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="form-group inline-group">
              <a href="" id="button-parent" class="btn btn-default">Parent Folder</a> 
            </div>
            <div class="form-group inline-group">
              <a href="" id="button-refresh" class="btn btn-default">Refresh Page</a>
            </div>
            <div class="form-group inline-group">
              <button type="button" id="button-upload" class="btn btn-primary">Upload</button>
            </div>
            <div class="form-group inline-group">
              <button type="button" id="button-folder" class="btn btn-default">Create Folder</button>
            </div>
            <div class="form-group inline-group">
              <button type="button" id="button-delete" class="btn btn-danger">Delete</button>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="input-group">
              <input type="text" name="search" value="" placeholder="" class="form-control">
              <span class="input-group-btn">
    <button type="button" data-toggle="tooltip" title="<?php echo $button_search; ?>" id="button-search" class="btn btn-primary"><i class="fa fa-search"></i></button>
    </span>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

但是,form-group是一个属性,因此,它会删除新行中的每个form-element,所以要么你可以添加另一个类.inline-group和make如图所示display:inline-block

答案 1 :(得分:1)

这是因为您在模式中使用了.row.row没有填充或边距。如果你不想改变你的标记,那么一点点“黑客”可能是

.modal-body .row {
   padding-bottom: 16px;
}

以上和你的代码在小提琴 - &gt;的 http://jsfiddle.net/zfLsmogx/