html - 无法使用 CSS 创建页脚

标签 html css user-interface frontend footer

我正在尝试将一个 div 附加到页面底部。此页面不可滚动,但我无法按像素设置顶部,因为它需要响应屏幕尺寸。我想要的只是页面底部的一个 div,它占据 100% 的水平空间和 20% 的垂直空间。

我尝试过的:

  • 使 parent 亲戚和 child 绝对。
  • 设置 parent 的min-height: 100%

这是我的代码:

<html>
    <head>
        <title>Forget It</title>
        <link rel="stylesheet" href="../static/styles.css">
    </head>
    <body>
        <div class='parent'>
            <div class='ground'></div>
        </div>
    </body>
</html>
html {
    height: 100%;
}

body {
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: #96b4ff;
}

.parent {
    position: relative;
    min-height: 100%;
}

.ground {
    position: absolute;
    height: 20%;
    bottom: 0;
    background-color: #2cb84b;
}

有什么想法吗?谢谢!

最佳答案

只需将 width: 100%; 应用到 .ground 即可使 div 占据全宽。

html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: #96b4ff;
}

.parent {
  position: relative;
  min-height: 100%;
}

.ground {
  position: absolute;
  height: 20%;
  width: 100%;
  bottom: 0;
  background-color: #2cb84b;
}
<div class='parent'>
  <div class='ground'>footer</div>
</div>

关于html - 无法使用 CSS 创建页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58461210/

相关文章:

php - 如何通过单击按钮自动发送电子邮件?

javascript - JQuery 无法通过 val() 函数获取正确的值

jquery - AngularJS中获取被点击元素数据的值

javascript - 使用 jekyll-assets 缩小 CSS/JS 的问题

html - 列表样式的 CSS 属性应该放在哪里?

jquery - 如何在灯箱弹出窗口中显示内联内容?

javascript - 什么是好的 JavaScript 超高级 UI 框架?

javascript - 如何让JS在缓存中存储随机元素?

Android:如何在用户释放按钮时切换 ImageButton 的图像?

user-interface - 如何 "stream"我屏幕的一部分到另一部分