上下固定中间自适应布局

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

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>
相关推荐
老前端的功夫2 小时前
Vue 3 性能深度解析:从架构革新到运行时的全面优化
javascript·vue.js·架构
天天扭码2 小时前
如何实现流式输出?一篇文章手把手教你!
前端·aigc·ai编程
前端 贾公子2 小时前
vue移动端适配方案 === postcss-px-to-viewport
前端·javascript·html
GISer_Jing3 小时前
AI营销增长:4大核心能力+前端落地指南
前端·javascript·人工智能
明远湖之鱼4 小时前
一种基于 Service Worker 的渐进式渲染方案的基本原理
前端
前端小端长4 小时前
Vue 中 keep-alive 组件的原理与实践详解
前端·vue.js·spring
FeelTouch Labs4 小时前
Nginx核心架构设计
运维·前端·nginx
雪球工程师团队5 小时前
别再“苦力”写后台,Spec Coding “跑” 起来
前端·ai编程
m0_471199635 小时前
【场景】前端怎么解决离线收银、数据同步异常等场景问题
前端·javascript