上下固定中间自适应布局

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

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>
相关推荐
好_快30 分钟前
Lodash源码阅读-isNative
前端·javascript·源码阅读
好_快42 分钟前
Lodash源码阅读-reIsNative
前端·javascript·源码阅读
好_快44 分钟前
Lodash源码阅读-baseIsNative
前端·javascript·源码阅读
好_快1 小时前
Lodash源码阅读-toSource
前端·javascript·源码阅读
aerror1 小时前
VsCode/Cursor workbench.desktop.main.js 的入口
javascript·ide·vscode
Oneforlove_twoforjob1 小时前
volta node npm yarn下载安装
前端·npm·node.js
咖啡の猫1 小时前
npm与包
前端·npm·node.js
徐福记c1 小时前
npm install -g @vue/cli 方式已经无法创建VUE3项目
前端·vue.js·npm
小王不会写code1 小时前
npm install时卡在reify:rxjs: timing reifyNode:node_modules/core-js
前端·javascript·npm
慕钦。1 小时前
图像滑块对比功能的开发记录
前端·javascript·css·html5