利用css+div 做一個簡單置中結構

來源:互聯網
上載者:User

css:

#a1{ width:400px;height:200px; margin:0 auto;}
.b{float:left;width:200px;height:200px;background-color:#666666;}
.b1{float:left;width:200px;height:200px;background-color:#666666;}

html:

<div id="a1">
<div class="b">第一個</div>
<div class="b1">第二個</div>
</div>

 

代碼很簡單。說明:float用來實現2個元素並排排列;margin用來實現簡單的置中排列。

id=a1 的div其實啟動完全融合b b1元素的容器,為什麼這樣做,是因為margin 和float 互斥性。

其結果:

 

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.