如何删除bootstrap中列或网格之间的间距?

时间:2016-05-28 15:00:22

标签: html css twitter-bootstrap twitter-bootstrap-3

我正在尝试使用bootstrap网格构建一个平铺视图,但我不想要任何相邻列或行之间的间距。我试过很多方法去除,但我无法。任何人都可以帮忙吗?

以下是代码

<div class="container">
    <div class="row">
        <div class="col-lg-8 col-sm-12 col-md-8 col-xs-12">

            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
                <div class="col-lg-6 col-sm-12 col-md-6 col-xs-12">
                    //a vertical long image
                </div>
                <div class="col-lg-6 col-sm-12 col-md-6 col-xs-12">

                    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
                        //square image
                    </div>
                    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
                        //square image
                    </div>

                </div>

            </div>
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
                <!-- <horizontal image> -->
            </div>
        </div>
        <div class="col-lg-4 col-sm-12 col-md-4 col-xs-12 pull-right">
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" >
                 //square image
            </div>
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" >
             //vertical long image
            </div> 
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:1)

Bootstrap不提供此类功能,但很容易拥有网格列而没有额外的空间。

.no-gutter > [class*='col-'] {
    padding-right:0;
    padding-left:0;
}

您可以通过将.no-gutter类添加到.row类来轻松使用它。

<div class="row no-gutter">
    <div class="col-md-4">
        ...
    </div>
    <div class="col-md-4">
        ...
    </div>
    <div class="col-md-4">
        ...
    </div>
</div>

来源:https://scotch.io/bar-talk/bootstrap-3-tips-and-tricks-you-still-might-not-know

答案 1 :(得分:1)

col-*-*默认为padding-left/right: 15px,因此您需要重置为0

&#13;
&#13;
.container [class^="col"] {
  padding-left: 0;
  padding-right: 0;
  background: red
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-lg-8 col-sm-12 col-md-8 col-xs-12">

      <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
        <div class="col-lg-6 col-sm-12 col-md-6 col-xs-12">
          //a vertical long image
        </div>
        <div class="col-lg-6 col-sm-12 col-md-6 col-xs-12">

          <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
            //square image
          </div>
          <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
            //square image
          </div>

        </div>

      </div>
      <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
        <!-- <horizontal image> -->
      </div>
    </div>
    <div class="col-lg-4 col-sm-12 col-md-4 col-xs-12 pull-right">
      <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
        //square image
      </div>
      <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
        //vertical long image
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;