上下固定中间自适应布局

实现上下固定中间自适应布局

1.通过position:absolute实现

定义如下结构

<body>

<div class="container">

<div class="top"></div>

<div class="center"></div>

<div class="bottom"></div>

</div>

</body>

style实现如下:

html 复制代码
<style>
			body,
			html {
				width: 100%;
				height: 100%;
				background-color: yellow;
				margin: 0;
				padding: 0;
			}
			.container {
				height: 100%;
			}
			.top,
			.bottom {
				width: 100%;
				height: 100px;
				background-color: red;
			}
			.bottom {
				background-color: green;
			}

			.center {
				position: absolute;
				width: 100%;
				/* height: 100%; */
				/* margin-bottom: 100px; */
				top: 100px;
				bottom: 100px;
				background-color: aqua;
			}
		</style>

2.通过flex布局实现,父布局高度100%,display:flex;flex-direction: column;设置纵向排列,中间设置flex:1;具体实现如下:

html 复制代码
<style>
			body,
			html {
				width: 100%;
				height: 100%;
				background-color: yellow;
				margin: 0;
				padding: 0;
			}
			.container {
				height: 100%;
				/* display: flex;
				flex-direction: column;
				width: 100%; */
			}
			.top,
			.bottom {
				width: 100%;
				height: 100px;
				background-color: red;
			}
			.bottom {
				background-color: green;
			}

			.center {
				position: relative;
				width: 100%;
				/* flex: 1; */
				height: 100%;
				/* margin-bottom: 100px; */
				/* top: 100px; */

				background-color: aqua;
			}
		</style>
相关推荐
m***D286几秒前
React生态系统
前端·react.js·前端框架
b***74884 分钟前
React计算机
前端·react.js·前端框架
q***T5837 分钟前
React案例
前端·react.js·前端框架
闲人编程14 分钟前
Python协程的演进:从yield到async/await的完整历史
java·前端·python·async·yield·await·codecapsule
驳是1 小时前
TS 项目升级 React 18 到 19 的一些事情
前端·react.js·typescript
禁止摆烂_才浅1 小时前
React - 【useEffect 与 useLayoutEffect】 区别 及 使用场景
前端·react.js
5***o5001 小时前
React安全
前端·安全·react.js
喵个咪2 小时前
Qt 6 实战:C++ 调用 QML 回调方法(异步场景完整实现)
前端·c++·qt
g***B7382 小时前
JavaScript数据可视化应用
javascript·信息可视化·数据分析
F***c3252 小时前
React自然语言处理应用
前端·react.js·自然语言处理