上下固定中间自适应布局

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

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>
相关推荐
鸡吃丸子7 小时前
如何编写一个高质量的AI Skill
前端·ai
我命由我123457 小时前
Element Plus 2.2.27 的单选框 Radio 组件,选中一个选项后,全部选项都变为选中状态
开发语言·前端·javascript·html·ecmascript·html5·js
Luna-player7 小时前
第3章 Spring Boot的Web应用支持,个人学习笔记
前端·spring boot·学习
bugcome_com7 小时前
【ASP.NET Web Pages】页面布局核心实战:从复用性到安全性,打造一致化网站界面
前端·后端·asp.net
Sylus_sui7 小时前
Class 模型 + 跨组件状态(@Observed)+ 网络请求封装 + 本地存储全部是鸿蒙 Next/Stage 模型标准写法
前端
代码栈上的思考7 小时前
消息队列持久化:文件存储设计与实现全解析
java·前端·算法
weixin_443478517 小时前
flutter组件学习之卡片与列表
javascript·学习·flutter
moreen7 小时前
Koa3.1.2 迁移, 持续更新中
javascript
踩着两条虫7 小时前
去“AI味儿”实操手册:从“机器脸”到“高级脸”,只差这三步!
前端·vue.js·ai编程
qq_211387478 小时前
基于LangGraph多agent
开发语言·前端·javascript·agent·langgraph