html - 无法使用 CSS 创建页脚
问题描述
我正在尝试将 div 附加到页面底部。此页面不可滚动,但我无法按像素设置顶部,因为它需要响应屏幕尺寸。我想要的只是页面底部的一个 div,它占据了 100% 的水平空间和 20% 的垂直空间。
我试过的:
- 使父相对和子绝对。
- 设置父母的
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>
推荐阅读
- gradle - 为什么 gradle-clojure 插件会跳过 compileClojure 任务?
- python - 损失函数 Keras out_dim > 1
- joomla - Joomla - 方便的模板升级
- python-2.7 - NameError:全局名称“MyClass”未在 Pepper/Nao 中定义
- c - 使用指针删除链表中的节点
- python - 为什么 selenium 的 move_by_offset 函数有时会在执行前等待(Python/Chrome)
- java - 将 JPanel 从另一个项目添加到 JFrame
- ruby-on-rails - 打开 rails 控制台或执行 rake db:create 时出错
- python - 为什么熊猫不创建excel文件?
- r - R:按名称列出的与数据框大小不等的命名数字列