CSS两双列布局

1、使用绝对定位

.aside{
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 180px;
}

.main{
    width: 100%;
    margin-left: 180px;
}

2、使用浮动

.aside{
    width: 100px;
    background-color: red;
    float: left;
    height: 100%;
}
.main{
    margin-left: 110px;
    width: 100%;
    height: 100%;
    background-color: green;
}

3、利用浮动和overflow

.one {
    float: left;
    height: 100%;
    width: 30%;
    background-color: blue;
}
.two {
    overflow: auto;
    height: 100%;
    background-color: red;
}

4、利用flex布局

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CSS圣杯布局和双飞翼布局都是三栏布局,其中主要内容区域在最中间,左右侧是侧边栏。它们的目的是为了解决传统三栏布局固定中间宽度,侧边栏无法等高的问题。 CSS圣杯布局的实现: HTML结构如下: ``` <div class="container"> <div class="main">主要内容</div> <div class="left">左侧边栏</div> <div class="right">右侧边栏</div> </div> ``` CSS样式如下: ``` .container { display: table; width: 100%; table-layout: fixed; border-spacing: 0; } .main { display: table-cell; width: 100%; background-color: #fff; } .left { display: table-cell; width: 200px; background-color: #ccc; position: relative; left: -200px; margin-left: -100%; } .right { display: table-cell; width: 200px; background-color: #ccc; position: relative; right: -200px; margin-right: -100%; } ``` 实现原理:通过将容器设置为table,主要内容区域和侧边栏都设置为table-cell,实现三栏等高。通过设置负的margin和left/right来实现侧边栏的位置偏移。 双飞翼布局的实现: HTML结构如下: ``` <div class="container"> <div class="main">主要内容</div> </div> <div class="left">左侧边栏</div> <div class="right">右侧边栏</div> ``` CSS样式如下: ``` .container { padding-left: 200px; padding-right: 200px; } .main { float: left; width: 100%; background-color: #fff; } .left { float: left; width: 200px; margin-left: -100%; background-color: #ccc; } .right { float: left; width: 200px; margin-left: -200px; background-color: #ccc; } ``` 实现原理:通过设置主要内容区域的宽度为100%,再通过padding将左右侧的宽度撑开。通过设置负的margin和left来实现侧边栏的位置偏移。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值