3 回答

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個贊
設(shè)置text-align:center;為父div和margin:auto;子div。
#parent {
text-align:center;
background-color:blue;
height:400px;
width:600px;
}
.block {
height:100px;
width:200px;
text-align:left;
}
.center {
margin:auto;
background-color:green;
}
.left {
margin:auto auto auto 0;
background-color:red;
}
.right {
margin:auto 0 auto auto;
background-color:yellow;
}
<div id="parent">
<div id="child1" class="block center">
a block to align center and with text aligned left
</div>
<div id="child2" class="block left">
a block to align left and with text aligned left
</div>
<div id="child3" class="block right">
a block to align right and with text aligned left
</div>
</div>
這是一個幾乎可以集中所有內(nèi)容的好資源。
http://howtocenterincss.com/
添加回答
舉報(bào)