我有塊,塊內有三個框。該CSS是爲什麼我不能在div中水平居中組件?
.blocks {
display: block;
margin: 0 auto;
width: 60%;
height: 350px;
}
.box1, .box2, .box3 {
width: 33.333%;
height: 300px;
vertical-align: top;
display: inline-block;
zoom: 1;
}
在框中,有一個圖像和一個文本。我想讓它們水平居中。 所以我這樣做
.box1, .box2, .box3 {
width: 33.333%;
height: 300px;
vertical-align: top;
display: inline-block;
zoom: 1;
margin-left: auto;
margin-right: auto;
}
<div class="blocks">
<div class="col-sm-4 col-xs-4 box1" style="background-color:lavender;">
<!-- One image and text here -->
</div>
<div class="col-sm-4 col-xs-4 box2" style="background-color:lavenderblush;">
<!-- One image and text here -->
</div>
<div class="col-sm-4 col-xs-4 box3" style="background-color:lavender;">
<!-- One image and text here -->
</div>
</div>
如何將組件水平居中在div?
你能做出的jsfiddle或plnkr? – martin
發佈你的html標記或小提琴會更好 – Gintoki
'text-align:center'? – Morpheus