这是我的基本HTML:
<div class="col-lg-12">
<div class="col-lg-4 center-block main-text center-text marg-small boxed">
<div class="random">Some Text</div>
<div class="col-lg-6 marg-small ">
<div id="pick_channel" class="boxed orange">
<div class="square vertical">Channel</div>
</div>
<div id="pick_objective" class="boxed orange">
<div class="square vertical">Objective</div>
</div>
</div>
</div>
</div>
相关的CSS:
.boxed{
display:flex;
flex-direction: column;
flex-wrap:nowrap;
align-items: center;
}
.square {
height:100px;
width:100%;
display:flex;
align-self:center;
margin-bottom: 10px;
}
.vertical{
}
我试图将id
s pick_channel
和pick_objective
作为矩形与文本&#34;频道&#34;和&#34;目标&#34;垂直和水平居中,各自为divs
。我已经尝试了很多组合,但无法弄明白。
答案 0 :(得分:1)
你去吧
.boxed {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
height: 100px;
width: 100%;
margin: 10px 0;
}
.square {
margin-bottom: 10px;
width: 100%;
text-align: center;
}
.orange {
background: orange;
}
.center_content {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
<div class="col-lg-4 center_content">
<div class="col-lg-6 marg-small ">
<div id="pick_channel" class="boxed orange">
<div class="square vertical">Channel</div>
</div>
<div id="pick_objective" class="boxed orange">
<div class="square vertical">Objective</div>
</div>
</div>
</div>
答案 1 :(得分:1)
这样的事情:
.boxed {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-items: center;
}
.square {
height: 100px;
width: 100px;
/* display: flex; */
/* align-self: center; */
margin-bottom: 10px;
border: 1px solid gray;
text-align: center;
line-height: 100px;
}
&#13;
<div class="col-lg-12">
<div class="col-lg-4 center-block main-text center-text marg-small boxed">
<div class="random">Some Text</div>
<div class="col-lg-6 marg-small ">
<div id="pick_channel" class="boxed orange">
<div class="square vertical">Channel</div>
</div>
<div id="pick_objective" class="boxed orange">
<div class="square vertical">Objective</div>
</div>
</div>
</div>
</div>
&#13;