css实现左右宽度固定,中间自适应及上下宽度固定,中间自适应的方法

一、左右宽度固定,中间宽度自适应
1. 使用浮动布局

(1)左侧元素与右侧元素优先渲染,分别向左和向右浮动
(2)中间元素在文档流的最后渲染,则会自动插入到左右两列元素的中间
在这里插入图片描述

2. 使用弹性布局

父元素开启flex,中间设置flex:1
在这里插入图片描述

3. 使用绝对定位

在这里插入图片描述

二、实现上下宽度固定,中间自适应
1. 绝对定位
	<head>
		<meta charset="utf-8">
		<style type="text/css">
			body {
				height: 100%;
				width: 100%;
			}
			.box>div {
				position: absolute;
				width: 100%;
			}
			.top {
				top: 0;
				height: 200px;
				background-color: antiquewhite;
			}
			.bottom {
				bottom: 0;
				height: 200px;
				background-color: aqua;
			}
			.center {
				top: 200px;
				bottom: 200px;
				background-color: gold;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<div class="top"></div>
			<div class="center"></div>
			<div class="bottom"></div>
		</div>
	</body>			
2. flex弹性布局
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style type="text/css">
			body {
				height: 100%;
				width: 100%;
			}
			.box {
				display: flex;
				width: 100%;
			}
			.top {
				height: 200px;
				background-color: antiquewhite;
			}
			.bottom {
				height: 200px;
				background-color: aqua;
			}
			.center {
				flex: 1;
				background-color: gold;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<div class="top"></div>
			<div class="center"></div>
			<div class="bottom"></div>
		</div>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值