我对Web开发一般都比较新,并且遇到布局危机:我有一个 container-fluid ,它将行分成两个* col-md -6 * S。在col-md-6中,我希望能够水平放置元素。如我的代码/图片所示;我试图制作一个简单的div,它是按钮组高度的95%并显示在它旁边......但是它显示在它下面而且非常短(我想要它和按钮组一样高。在这样的Bootstrap中,调整/定位元素的协议是什么样的?
<div class="container-fluid">
<div class="row">
<div class="col-md-6" style="background-color: lightcyan">
<div class="btn-group-vertical btn-group-lg">
<button type="button" class="btn btn-primary">Quick Select</button>
<button type="button" class="btn btn-primary">Show in Depth</button>
<button type="button" class="btn btn-primary">Delete Product</button>
</div>
<div id="prod_view">
yo
</div>
CSS:
#prod_view{
background: lightcoral;
width: 69%;
height: 95%;
margin-left: 23%;
border: solid;
}
我希望“yo”框更加矩形,位于按钮组的右侧。
答案 0 :(得分:3)
这是一个灵活的布局,可以做到这一点。您可以使用justify-content
属性来影响水平对齐,align-items
会影响垂直对齐。这是flexbox https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.custom-row {
display: flex;
justify-content: space-between;
}
.custom-row > div:last-child {
width: 69%;
}
#prod_view {
height: 95%;
background: lightcoral;
border: solid;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 custom-row" style="background-color: lightcyan">
<div class="btn-group-vertical btn-group-lg">
<button type="button" class="btn btn-primary">Quick Select</button>
<button type="button" class="btn btn-primary">Show in Depth</button>
<button type="button" class="btn btn-primary">Delete Product</button>
</div>
<div>
<div id="prod_view">
yo
</div>
</div>
</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
另一种方法是使用单个flexbox类。将其添加到row
和col-md-6
:
.flex {
display: flex;
}
<div class="container-fluid">
<div class="row flex">
<div class="col-md-6 flex" style="background-color: lightcyan">
<div class="btn-group-vertical btn-group-lg">
<button type="button" class="btn btn-primary">Quick Select</button>
<button type="button" class="btn btn-primary">Show in Depth</button>
<button type="button" class="btn btn-primary">Delete Product</button>
</div>
<div id="prod_view">
yo
</div>
</div>
</div>
</div>
http://www.codeply.com/go/wvCRJ0ufEB
在Bootstrap 4中,flexbox is default所以不需要额外的课程。