首頁  >  文章  >  web前端  >  css實現兩欄佈局的三種方法介紹(程式碼)

css實現兩欄佈局的三種方法介紹(程式碼)

不言
不言原創
2018-08-21 10:17:163719瀏覽

這篇文章帶給大家的內容是關於css實現兩欄佈局的三種方法介紹(程式碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。

1、浮動佈局

左側欄固定寬度向左浮動,右側主要內容則用margin-left留出左側欄的寬度,預設寬度為auto,自動填滿剩下的寬度。

<div class="one"></div>
 
<div class="two"></div>
        .one{
            float: left;
            width: 200px;
            height: 200px;
            background: darkcyan
        }
        .two{
            margin-left: 200px;
            height: 200px;
            background: salmon
        }

右側固定寬度,左側自適應則是同理,只要將固定欄右浮動,使用margin-right空出其寬度即可。

    <div class="one"></div>
    <div class="two"></div>
        .one{
            float: right;
            width: 200px;
            height: 200px;
            background: darkcyan
        }
        .two{
            margin-right: 200px;
            height: 200px;
            background: salmon
        }

2、浮動佈局負外邊距(雙飛翼佈局的兩欄版本)

        <div class="aside"></div>
    <div class="main">
        <div class="content"></div>
    </div>
        .aside{
            width: 300px;
            height: 100px;
            background:darkcyan;
            margin-right: -100%;
            float: left;
        }
        .main{
            width: 100%;
            float: left;
        }
        .content{
            margin-left: 300px;
            background: salmon;
        }

#3、絕對定位

    <div class="left"></div>
    <div class="right"></div>
        .left{
            width: 200px;
            height: 200px;
            position: absolute;
            background: darkcyan
        }
        .right{
            height: 200px;
            margin-left:200px; 
            background: salmon;
        }

相關推薦:

Css佈局系列-上下兩欄佈局_html/css_WEB-ITnose

CSS:三欄佈局,兩邊固定,中間自適應_html/css_WEB-ITnose

css 多欄自適應佈局_html/css_WEB-ITnose

以上是css實現兩欄佈局的三種方法介紹(程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn