使用display:flex;实现两栏布局和三栏布局

本文介绍如何使用CSS中的display:flex属性来实现两栏及三栏布局。通过设置不同的flex属性值,可以轻松调整各栏目宽度,实现响应式网页设计。文中提供了具体代码示例。

一、使用display:flex;实现两栏布局

body,div{margin:0px;padding:0px;}
.flex-container{display:flex;height:300px;}
.item{padding:6px;}
.item1{flex:0 0 auto;background-color:#999;width:200px;}
.item2{flex:1 1 auto;background-color:#484;}
<div class="flex-container">
        <div class="item item1">这是左侧内容</div>
        <div class="item item2">这是右侧内容</div>
</div>

 

二、使用display:flex;实现三栏布局

body,div{margin:0;padding:0;}
.flex-container{display:flex;height:300px;}
.item{padding:5px;width:200px;}
.item1,.item3{flex:0 0 auto;background-color:#372;}
.item2{flex:1 1 auto;background-color:#efe;}
<div class="flex-container">
        <div class="item item1">这是左侧内容</div>
        <div class="item item2">这是中间内容</div>
        <div class="item item3">这是右侧内容</div>
</div>

 

转载于:https://www.cnblogs.com/snowcan/p/7561019.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值