DIV+CSS 三欄布局

來源:互聯網
上載者:User

1.要求:如中的,三欄目布局,中間的MAIN是自適應瀏覽器的寬度,左LEFT固定寬200PX,右RIGHT固定寬200PX;

.right,.left{height:300px;width:200px;}.right{ float:right;background:#000000;}.left{ float:left;background:#009933;}.main{background:#F60; height:300px;}
     <div class="right">RIGHT</div>    <div class="left">LEFT</div>    <div class="main">MAIN</div>    

2.現在要求先載入MIAN,其它要求同上面一樣;

總結:主要是利用浮動元素的負外邊距;

  並且要理解float和絕對位置,這兩種元素的寬度都是根據內容的寬度來的。

  相對定位和區塊層級元素,如果不設定寬,都是100%(相對於父級的寬)

  DEMO下載

.boxmain{float:left;margin-right:-200px;width:100%;}.right,.left{height:300px;width:200px; z-index:1;}.right{ position:absolute; right:0; background:#000000;}.left{position:absolute;left:0; background:#009933;}.main{margin-right:200px;background:#F60; height:300px;margin-left:200px;}

 

    <div class="boxmain">        <div class="main">main</div>        </div>    <div class="left">LEFT</div>    <div class="right">RIGHT</div>
相關文章

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.