上下固定中间自适应布局

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

1.通过position:absolute实现

定义如下结构

<body>

<div class="container">

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

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

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

</div>

</body>

style实现如下:

<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;具体实现如下:

<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>

相关推荐

  1. CSS两侧固定中间适应

    2024-02-09 06:04:03       23 阅读
  2. Vue3使用 xx UI解决布局高度适应

    2024-02-09 06:04:03       41 阅读
  3. UGUI父对象适应子元素布局解决方案

    2024-02-09 06:04:03       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-09 06:04:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-09 06:04:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-09 06:04:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-09 06:04:03       18 阅读

热门阅读

  1. C#面:什么是Code-Behind技术

    2024-02-09 06:04:03       28 阅读
  2. PostgreSQL 与 MySQL 相比,优势何在?

    2024-02-09 06:04:03       36 阅读
  3. ASP.NET Core 7 MVC 使用 Ajax 和控制器通信

    2024-02-09 06:04:03       33 阅读
  4. C语言如何控制输出⻓度?

    2024-02-09 06:04:03       33 阅读
  5. 【flink状态管理(四)】MemoryStateBackend的实现

    2024-02-09 06:04:03       27 阅读