两边定宽,中间自适应的方法总结

两边定宽,中间自适应的方法总结。
  1. float + margin实现:
		//html
			<div class="parent">
				<div class="left">Left</div>
				<div class="right">Right</div>
				<!--特别需要注意:自适应宽度的div必须放在最后,如果把right div放到最后会被挤下来-->
				<div class="conter">Conter</div> 
			</div>
		//css
			.parent{
				width: 100%;
				height: 300px;
				background-color: white;
				box-sizing: border-box;
			}
			.left{
				width: 300px;
				height: 300px;
				background-color: coral;
				float: left;
			}
			.right{
				width: 300px;
				height: 300px;
				background-color: cornflowerblue;
				float: right;
			}
			.conter{
				margin: auto 300px;
				height: 300px;
				background-color: darkcyan;
			}
		/**
		*	左右盒子分别向左右浮动
		*	中间盒子设置 margin:auto 300px;
		*	上下自适应  左右各距离父盒子300px
		**/
  1. flex布局发(兼容性一般):
			//html
			<div class="parent"> 
				<div class="left"></div> 
				<div class="right"></div> 
				<div class="center"></div> 
			</div>
			//css
			.parent {
				display: flex;
				height: 300px;
			}

			.left {
				width: 300px;
				height: 300px;
				background-color: red;
				
			}

			.right {
				width: 300px;
				height: 300px;
				background-color: yellow;
			}

			.center {
				flex: 1;
				height: 300px;
				background-color: green;
			}

  1. 定位法
		//html
		<div class="parent"> 
			<div class="left"></div> 
			<div class="right"></div> 
			<!--特别需要注意:自适应宽度的div必须放在最后,如果把right div放到最后会被挤下来-->
			<div class="center"></div> 
		</div>
		//css
		.parent {
				width: 100%;;
				height: 300px;
			}

			.left {
				width: 300px;
				height: 300px;
				position: absolute;
				left: 0;
				background-color: red;
			}

			.right {
				width: 300px;
				height: 300px;
				position: absolute;
				right: 0;
				background-color: yellow;
			}

			.center {
				margin: auto 300px;
				height: 300px;
				background-color: green;
			}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值