我已经尝试过许多解决此问题的方法,但是找不到正确的Bootstrap方式。我想使用网格(或列)构建一个响应式简单网站,但在每一行和每一列之间都留有空隙(类似于FOLDY网格系统为您自动完成的工作)。我的以下html代码片段以及该页面在屏幕上的截图。
<div class="container-fluid">
<div class="row">
<div class="col-lg-6 test">half</div>
<div class="col-lg-6 test">half</div>
</div>
<div class="row">
<div class="col-md-4 test">third</div>
<div class="col-md-4 test">third</div>
<div class="col-md-4 test">third</div>
</div>
<div class="row">
<div class="col-md-10 test">10</div>
<div class="col-md-2 test">2</div>
</div>
</div>
.row{
background-color: #eee; /* This changes colour of my background grid */
}
链接到Bootstrap:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
答案 0 :(得分:1)
问题在于您正在为行应用背景,因此列之间的间隙将仅显示行背景。
但是!如果您在各列上设置背景,则可能会遇到相同的问题,因为引导程序使用列https://getbootstrap.com/docs/4.2/layout/grid/#columns-and-gutters
上的填充来创建该间隙您可以做的是使用100%的可用空间在该子项上设置背景,以该子项为背景。
编辑:代码将像这样https://jsfiddle.net/dnhv9x0p/
.row {
width: 100%;
margin: 0;
padding: 0;
}
.row [class^='col-'] {
padding: 3px 5px; // chenge the size of the gaps here
}
.row [class^='col-'] span { //i've used a span, but you can use any element inside columns, just make it a block
background: #bbb;
display: block;
}
答案 1 :(得分:0)
为测试班级增加边距
--enable-profile