左側固定寬度,右側自適應寬度的CSS布局_經驗交流

來源:互聯網
上載者:User
BI上有高手專門討論了這種布局方法,但他用了較多的hack,還迴避了IE6的dtd。我在實際使用中,發現迴避掉IE6的dtd定義後,會導致ajax模態框無法置中(VS的一個控制項,自動產生的程式碼,很難修改)。 於是自己寫了個簡單的左右兩列的布局,沒用到什麼hack,很簡單,只是練手用用。

css代碼:left和right都貼住左側。設定left在right上面(z-index);在right內加個放內容的層(content);設定content距離right的左側為200px,即剛巧等於left的寬度。
複製代碼 代碼如下:
* {margin:0; padding:0; list-style:none; }
.wrapper {width: 100%; }
.left {width:200px;background:#fcc; position:absolute; left:0 ;z-index:1 }
.right {width:100%;background:#ccc; position:absolute;left:0}
.content {margin-left:200px;background:#ffc; }

完整代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> * {margin:0; padding:0; list-style:none; } .wrapper {width: 100%; } .left {width:200px; background:#fcc; position:absolute; left:0 ;z-index:1 } .right {width:100%; background:#ccc; position:absolute; left:0} .content {margin-left:200px; background:#ffc; } </style> </head> <body> 左側固定寬度200px 右側寬度自動適應 </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
  • 相關文章

    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.