css实现两栏布局的方法有哪些

这篇文章将为大家详细讲解有关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
        }

css实现两栏布局的方法有哪些

右侧固定宽度,左侧自适应则是同理,只要将固定栏右浮动,使用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
        }

css实现两栏布局的方法有哪些

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;
        }

css实现两栏布局的方法有哪些

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实现两栏布局的方法有哪些就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。