通過css實現div的置中

來源:互聯網
上載者:User

做網頁的布局的時候,為了美觀經常需要把文字圖片等置中。習慣使用table布局後發現很難用div來實現相同的效果。其實會者不難,只要通過下面的一段代碼就可以方便得實現div得置中,而且在例子中我還實現了兩個側欄,通過這個布局基本可以滿足大多數網頁整體布局的需要了。 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
 3 <head profile="http://gmpg.org/xfn/11">
 4 </head>
 5 <body>
 6 <div style=" position:relative; margin-left:auto; margin-right:auto; width:786px; background-color:Purple;">
 7 <div style="width:500px; float:right">內容</div>
 8 <div style="background-color:Yellow; width:200px">側欄上</div>
 9 <div style="background-color:Blue; width:200px">側欄下</div>
10 </div>
11 </body>
12 </html>

代碼檔案下載

相關文章

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.