有没有办法通过纯HTML/CSS来做到这一点?这就是我想要实现的:

|---------------------------| <-- start of screen
|          header           |   fixed height
|---------------------------|
|                           |
|                           |
|          content          |   fill screen
|                           |
|                           |
|---------------------------| <-- end of screen
|          footer           |   auto
|---------------------------|

我看到了一些东西,但没有回答我的问题:

CSS grid let an item take the rest of available screen space

How to make CSS Grid with fixed header and footer with remainder in middle

How to make CSS Grid items take up remaining space?

Here's what I have so far (image)

body {
    width: 100%;
    min-height: 100%;
    margin: 0 0 0 0;
    background-color: gray;
}

.app-wrapper {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "header header header header"
        "contnt contnt contnt contnt"
        "footer footer footer footer"
    ;

    height: 100vh;
    width: 100%;
}

.header {
    grid-area: header;
    background-color: lightcoral;
}

.content {
    grid-area: contnt;
    background-color: aqua;
}

.footer {
    grid-area: footer;
    background-color: lightyellow;
}
<body>
    <div class="app-wrapper">
        <div class="header">
            header
        </div>
        <div class="content">
            content
        </div>
        <div class="footer">
            footer
        </div>
    </div>
</body>

推荐答案

使最后一行等于0,并在页脚上定义一个高度以覆盖0的效果

body {
  margin: 0;
  background-color: gray;
}

.app-wrapper {
  display: grid;
  grid-template-rows: auto 1fr 0; /* 0 for the last row */
  height: 100vh;
}

.header {
  background-color: lightcoral;
}

.content {
  background-color: aqua;
}

.footer {
  background-color: lightyellow;
  height: min-content; /* overide the 0 of the row */
}
<body>
  <div class="app-wrapper">
    <div class="header">
      header
    </div>
    <div class="content">
      content
    </div>
    <div class="footer">
      footer
    </div>
  </div>
</body>

Html相关问答推荐

注册组件不显示当我导航到注册站点

如何在angular 17.2中使用routerLink解决此错误

为什么我的搜索栏会出现在WONG位置?

平移变换下的SVG剪辑路径行为

防止position:relative的child在出界时收缩

我的Django应用程序中出现模板语法错误

div居中碰撞问题

有没有一种方法可以提高代码中tailwind 类名的可读性?

为什么index.html在Django中有这样的名称?

当div位于flexbox中时,如何使div的宽度与高度相同

如何使用 HTML 将对象数组发送到 Nodejs Express

如何为卡片块制作侧丝带样式

为什么溢出时overflow: auto框的底部有一个小间隙?

我在桌面版 html css 代码上给出了位置 margin-left margin-top 标签,如何将其删除到手机上以使其响应?

如何在 flex 项目中忽略子元素的宽度

显示填充正方形的图形的简单页面的 HTML 代码

提交前的验证表单未显示任何验证消息?

在 EJS 中将元素放置在彼此下方的列中

在 Vue 3 中使用 JavaScript 数组显示 FontAwesome 图标