CSS兩列調適型配置

來源:互聯網
上載者:User

標籤:高度自適應   style   blog   http   color   io   os   ar   div   

兩列布局,一邊固定,一邊自適應,很常見,可不見得都能寫好,就像我。

在一通搜尋後,總結了幾種方法。

 

1、CSS3 Flex-Box

其實我最早知道的是這種方法,之前也記錄過。

彈性方塊模型 (Flexible Box Model)筆記

 

2、來自div+css自適應兩列布局,一列定寬,一列自適應

代碼:

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Document</title><style>.main,.sitebar {    height: 300px;    font: bolder 20px/300px ‘微軟雅黑‘;    color: #fff;    text-align: center;}.main {    width: 100%;    float: left;}.main .content {    margin-left: 200px;    background-color: red;}.sitebar {    width: 200px;    float: left;    margin-left: -100%;    background-color: green;}</style></head><body><div class="main">    <div class="content">右側主體自適應區塊</div></div><div class="sitebar">左側定寬200px區塊</div></body></html>

效果:

3、來自經典DIV+CSS案例--兩列高度自適應

代碼:

<!DOCTYPE html><html><head><meta charset="utf-8"/><title>兩列高度自適應</title><style type="text/css">    * {         margin:0;        padding:0;    }    #main {        overflow:hidden;        text-align: center;        height: 300px;    }    .sidebar {        float:left;        width:150px;        background:#ff0000;    }    .content {        background:#333333;        overflow:hidden;        _float:left;/*相容IE6*/}    .row {        margin-bottom:-10000px;        padding-bottom:10000px;/*內外補丁是關鍵*/    }</style></head><body><div id="main">    <div class="sidebar row">        左側150px    </div>    <div class="content row">        右側自適應        <span style="float:right; font-size:0; position:relative; ">&nbsp;</span> <!--為了萬惡的ie6-->    </div></div></body></html>

效果:

CSS兩列調適型配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.