CSS 三栏布局

6 篇文章 0 订阅

1、浮动布局 float

<style>
.container{
 	width:100%;
 	height:100px;
 }
.left{
	width:250px;
	height:100%;
	background:red;
	float:left;
}
.right{
	width:250px;
	height:100%;
	background:pink;
	float:right;
}
.center{
	height:100%;
	background:blue;
}
</style>
<div class="container">
	<div class="left"></div>
	<div class="right"></div>
	<div class="center">浮动布局</div> //中间这一部分必须写在最后面
</div>

在这里插入图片描述优点:简单
缺点:当中间部分加载内容较多时,用户体验不好;当浏览器窗口所小到一定程度时,会发生错位
在这里插入图片描述
2、绝对定位布局 position

<style>
.left{
   	width:250px;
   	height:100px;
   	background:red;
   	position: absolute;
   	left: 0px;
   	top: 0px;
}
.right{
	width:250px;
	height:100px;
	background:pink;
	position: absolute;
	right: 0px;
	top: 0px;
}
.center{
	height:100px;
	background:blue;
}
</style>
<div class="container">
	<div class="left"></div>
	<div class="right"></div>
	<div class="center"></div> //中间这一部分必须写在最后面
</div>

在这里插入图片描述
优缺点同1
3、flex布局:个人超级喜欢的一种

<style>
.container{
 	width:100%;
 	display: flex;
 }
.left{
	width:250px;
	height:100px;
	background:red;
}
.right{
	width:250px;
	height:100px;
	background:pink;
}
.center{
	height:100px;
	background:blue;
	flex: 1;
}
</style>
<div class="container">
	<div class="left"></div>
	<div class="center">flex布局</div>  //区分上面两种的位置
	<div class="right"></div>
</div>

在这里插入图片描述
4、table布局

<style>
.container{
	width:100%;
	display: table;
}
.container div{
	display: table-cell;
}
.left{
	width:250px;
	height:100px;
	background:red;
}
.right{
	width:250px;
	height:100px;
	background:pink;
}
.center{
	height:100px;
	background:blue;
}
</style>
<div class="container">
	<div class="left"></div>
	<div class="center">table布局</div>
	<div class="right"></div>
</div>

在这里插入图片描述
5、Grid网格布局

<style>
.container{
	width:100%;
	display: grid;
	grid-template-rows: 100px; /*设置行高*/
	grid-template-columns: 250px auto 250px;/*设置列数属性*/
}
.left{
	background:red;
}
.right{
	background:pink;
}
.center{
	background:blue;
}
</style>
<div class="container">
	<div class="left"></div>
	<div class="center">Grid网格布局</div>
	<div class="right"></div>
</div>

在这里插入图片描述
6、圣杯布局
7、双飞翼布局
8、BFC规则
参考文档:
https://blog.csdn.net/ganyingxie123456/article/details/77054124
https://www.jianshu.com/p/8b308d63fe23

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值