简体   繁体   English

col-padding-如何在Bootstrap 3网格系统中调整装订线

[英]col-padding - How to adjust gutter in Bootstrap 3 grid system

How do I reduce the precise gap between the columns so the width of all col remain same and keeping them even with the rest of the page. 如何减小列之间的精确间距,以使所有列的宽度保持不变,并使它们与页面的其余部分保持一致。

 .blackbox { color: #fff; background: #000; } .content { background: #4679BD; } .pad-5 [class*="-3"] { padding-left:5px; padding-right:5px; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="blackbox">Hey. I'Black Box</div> </div> </div> <div class="row pad-5"> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> </div> </div> 

Note: 注意:

  • I tried couple of solutions from different answers asked here on SO but no luck or may be I'm missing something obvious. 我尝试了几种不同的解决方案,但都没有运气,或者可能是我缺少明显的东西。
  • <div class="col-xs-3"></div> is inside for each loop. 每个循环都在<div class="col-xs-3"></div>内。

Fiddle 小提琴

You can simply add in the CSS file the folowing code: 您可以简单地在CSS文件中添加以下代码:

.content{
    margin-left: -10px;
}

or another solution you can add new class: For Example: 或其他解决方案,您可以添加新类:例如:

<div class="content removespace">
<p>text here</p>
</div>

and new css class: 和新的CSS类:

.removespace{
    margin-left: -10px;
}

Vote up if this helped you 如果这对您有帮助,请投票

https://jsfiddle.net/Last_Fl00r/xqmfqe1h/ https://jsfiddle.net/Last_Fl00r/xqmfqe1h/

as you reduce the padding of col from 15px to 5px the <div class="row"> which has margin left and right 15px causing the col uneven, simple solution of this is adjust the margin left and right of <div class="row"> change its value from 15px to -5px and it will push back the cols inside and make them even and col's width will remain same and it doesn't effect the responsiveness. 当您将col的填充从15px减少到5px<div class="row">左右边距为15px导致col不均匀,这的简单解决方案是调整<div class="row">将其值从15px更改为-5px ,它将把cols推回内部并使它们均匀,而col的宽度将保持不变,并且不会影响响应速度。 just add following css to your style sheet 只需将以下CSS添加到样式表

.pad-5 {
    margin-left: -5px;
    margin-right: -5px;
}

 .blackbox { color: #fff; background: #000; } .content { background: #4679BD; } .pad-5 { margin-left: -5px !important; margin-right: -5px !important; } .pad-5 [class*="-3"] { padding-left:5px; padding-right:5px; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="blackbox">Hey. I'Black Box</div> </div> </div> <div class="row pad-5"> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> <div class="col-xs-3"> <div class="content"> <p>Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content Test Content</p> </div> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM