我有两列:
<div class="col-md-6"></div>
<div class="col-md-6"></div>
我怎么在它们之间加一个空格?
输出只是两个相邻的列,占据了整个页面的宽度。假设宽度设置为1000px,那么每个div将是500px宽。
如果我想在两者之间有一个100px的空间,我如何用Bootstrap自动实现这一点:div的大小将变成450px来补偿间距。
我有两列:
<div class="col-md-6"></div>
<div class="col-md-6"></div>
我怎么在它们之间加一个空格?
输出只是两个相邻的列,占据了整个页面的宽度。假设宽度设置为1000px,那么每个div将是500px宽。
如果我想在两者之间有一个100px的空间,我如何用Bootstrap自动实现这一点:div的大小将变成450px来补偿间距。
当前回答
这将是有用的。
.list-item { margin-right: -10 px; margin-top: 10 px; margin-bottom: 10 px; 边框:1px实体#eee; 填充:0 px; } < div class = " col-md-4”> < div class = "列表项”> 你的名字< h2 > < / h2 > < / div > < / div > < div class = " col-md-4”> < div class = "列表项" > < / div > < / div >
如果想要增加或减少框的右边的边距,只需编辑列表项的右边距属性。
样例输出
其他回答
这将是有用的。
.list-item { margin-right: -10 px; margin-top: 10 px; margin-bottom: 10 px; 边框:1px实体#eee; 填充:0 px; } < div class = " col-md-4”> < div class = "列表项”> 你的名字< h2 > < / h2 > < / div > < / div > < div class = " col-md-4”> < div class = "列表项" > < / div > < / div >
如果想要增加或减少框的右边的边距,只需编辑列表项的右边距属性。
样例输出
你可以使用带有边框属性的背景剪辑和盒子模型
.box{
box-sizing: border-box;
border: 3px solid transparent;
background-clip:padding-box;
}
<div class="row">
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
</div>
为了获得列之间特定宽度的间距,我们必须在标准Bootstrap的布局中设置填充。
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'); /* Check breakpoint at http://getbootstrap.com/css/#grid-media-queries */ @media (min-width: 992px) { .space-100-px > .row > .col-md-6:first-child { padding: 0 50px 0 0; /* The first half of 100px */ } .space-100-px > .row > .col-md-6:last-child { padding: 0 0 0 50px; /* The second half of 100px */ } } /* The result will be easier to see. */ .space-100-px img { width: 100%; height: auto; } <div class="container-fluid space-100-px"> <div class="row"> <div class="col-md-6"> <img src="http://placehold.it/450x100?text=Left" alt="Left"> </div> <div class="col-md-6"> <img src="http://placehold.it/450x100?text=Right" alt="Right"> </div> </div> </div>
我知道这篇文章有点过时,但我遇到了同样的问题。我的html的例子。
<div class="row">
<div class="col-xs-3">
<div class="form-group">
<label asp-for="FirstName" class="control-label"></label>
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<label asp-for="LastName" class="control-label"></label>
<input asp-for="LastName" class="form-control" />
<span asp-validation-for="LastName" class="text-danger"></span>
</div>
</div>
</div>
为了在组之间创建空间,我在site.css文件中通过减少5的负边距来覆盖bootstrap的-15px的边距。
我是这么做的……
.form-group {
margin-right: -10px;
}
我希望这能帮助到其他人。
使用bootstrap的.form-group类。你的情况是这样的:
<div class="col-md-6 form-group"></div>
<div class="col-md-6 form-group"></div>