CSS調適型配置(左右固定 中間自適應或者右側固定 左側自適應),css自適應

來源:互聯網
上載者:User

CSS調適型配置(左右固定 中間自適應或者右側固定 左側自適應),css自適應

   一: 右側固定寬度 左側自適應

  第一種方法:左側用margin-right,右側float:right  就可以實現。

    HTML代碼可以如下寫:
    <div class="box-left">
        <a href="" target="_blank">我是龍恩</a>
    </div>

  <div class="box-right">
        <a href="" target="_blank">我是龍恩</a>
    </div>

  CSS代碼可以如下寫:

    .box-left{height:300px;margin-right:300px;background:#DDD;}
    .box-right{width:300px;height:300px;float:right;background:#AAA;}

    如上代碼就可以實現效果。

    第2種方法:左側同樣用margin-right  右側採用絕對位置 如下代碼所示:

    HTML代碼如下:

    <div class="bd">
        <div class="bd-left">
            <a href="" target="_blank">我是龍恩</a>
        </div>
        <div class="bd-right">
            <a href="" target="_blank">我是龍恩</a>
        </div>
    </div>

 CSS代碼如下:

 .bd{position:relative;}
 .bd-left{height:300px;;margin-right:300px;background:#DDD;}
 .bd-right{width:300px;height:300px;position:absolute;top:0;right:0;background:#AAA;}

 第三種方法:右側浮動 且 用負margin值

 HTML代碼如下:

 <div class="wrap">
        <div class="wrap-left">
            <div class="left-con">
                <a href="" target="_blank">我是龍恩</a>
            </div>
        </div>
        <div class="wrap-right">
            <a href="" target="_blank">我是龍恩</a>
        </div>
    </div>

  CSS代碼如下:

  .wrap{overflow:hidden;background:#EEE;}
  .wrap-right{width:300px;position:relative;float:right;margin-left:-300px;background:#AAA;}
  .wrap-left{width:100%;float:left;}
  .left-con{margin-right:300px;background:#DDD;}
  .left-con,.wrap-right{height:300px;}

以上是我總結的三種html css 兩列布局方法(左側自適應 右側固定),如有不足的地方 請大家多多指教。下面我們來看看三列布局(左右固定 中間自適應的情況)。

 二:左右固定 中間自適應的情況

 我目前總結了2種方法 如下:

 第一種:左右側採用浮動 中間採用margin-left 和 margin-right 方法。

 代碼如下:

   <div style="width:100%; margin:0 auto;"> 
       <div style="width:200px; float:right; 這是右側的內容 固定寬度</div>
       <div style="width:150px; float:left; background:#6FF">這是左側的內容 固定寬度</div>
       <div style="margin-left:150px;margin-right:200px; 中間內容,自適應寬度</div>
    </div>

 第二種:左右兩側採用絕對位置 中間同樣採用margin-left margin-right方法:

 HTML代碼如下:

 <div class="l-sidebar"></div>
 <div class="mainbar"></div>
 <div class="r-sidebar"></div>

CSS代碼如下:

 .l-sidebar {
   width:200px;
   height:500px;
   position:absolute;
   top:0;
   left:0;
   background:blue;
}
.mainbar {
   margin-left:200px;
   height:500px;
   margin-right:300px;
   background:green;
}
.r-sidebar {
   width:300px;
  height:500px;
   position:absolute;
  top:0;
   right:0;
   background:blue;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.