三个盒子,左右定宽,中间自适应

html代码

    <div class="left">1111</div>	
	<div class="center">1212</div>	
	<div class="right">222</div>	

在这里插入图片描述
方法一:绝对定位

	<style type="text/css">
			.left{
				position: absolute;
				width: 100px;
				height: 300px;
				left: 0;
				background: #269ABC;
			}
			.right{
				position: absolute;
				width: 100px;
				height: 300px;
				background: #398439;
				right: 0;
			}
			.center{
				position: absolute;
				left: 100px;
				right:100px;
				height:300px;
				background:#669900;
			}
		</style>

方法二:flex布局
html代码

<div class=''div''>
	<div class="left">1111</div>	
	<div class="center">1212</div>	
	<div class="right">222</div>	
</div>
	.div{
				display: flex;
			}
			.left{
				width: 100px;
				height: 300px;
				left: 0;
				background: #269ABC;
			}
			.right{	
				width: 100px;
				height: 300px;
				background: #398439;
				right: 0;
			}
			.center{
				flex: 1;
				height:300px;
				background:#669900;
			} 

3、float布局

	<div class="left">1111</div>		
	<div class="right">222</div>	
	<div class="center">1212</div>

该布局法的好处是受外界影响小,但是不足是 三个元素的顺序,center一定要放在最后,center占据文档流位置,所以一定要放在最后,左右两个元素位置没有关系。当浏览器窗口很小的时候,右边元素会被挤到下一行。

		.left{
				width: 100px;
				height: 300px;
				float: left;
				background: #269ABC;
			}
			.right{	
				width: 100px;
				height: 300px;
				background: #398439;
				float: right;
			}
			.center{
				margin-left: 100px;
				margin-right:100px;
				height:300px;
				background:#669900;
			} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值