html - 将页脚固定到页面底部
问题描述
如何在居中时将页脚固定到页面底部?我这辈子都想不通。
我希望页脚以 50% 的比例位于页面底部的中心,但由于某种原因,左右边距不起作用。它坐在左边。
.navigation2 {
padding: 8px;
background-color: #888;
width: 50%;
margin-left: auto;
margin-right: auto;
position: fixed;
bottom: 0px;
}
<footer>
<div class="navigation2">
© 2019 - <a href="index.html">X</a>
</div>
</footer>
任何帮助将不胜感激。
解决方案
你可能只需要一点不同的数学方法。这可能会让你更接近你正在寻找的东西:
CSS:
.navigation2 {
padding: 8px;
background-color:#888;
left: 25%;
right: 25%;
position: fixed;
bottom: 0px;
}
另一种你可以做到的方式更加动态(无论页脚的宽度如何)并且可以更好地缩放,因此你的页脚在小屏幕上不会被挤压得那么大:
.navigation2 {
padding: 8px;
background-color:#888;
left: 50%;
transform:translatex(-50%);
position: fixed;
bottom: 0px;
}
推荐阅读
- visual-studio - 我可以将自动化测试用例与 Azure DevOps 中不同集合中的测试用例工作项相关联吗?
- html - 如何在 html/css 中制作水平图标列表?
- android - 用于读取和写入原始传感器数据的范围存储强制
- python - Python模拟正确的类/导入
- tinylog - 您好,我想知道是否有任何方法可以将 Tinylog 与需要 Log4J2 实现的应用程序一起使用。(适配器什么的)
- c - fork子能判断是fork还是vfork吗?
- linux - DNSMASQ 为不同的子网提供不同的 dns 结果
- ios - 如何设置外部存储或设置自定义路径以在 Android 上的 OS 10 和 OS 11 中下载地图?
- visual-studio - 如何设置相同的键来切换 Visual Studio 中当前块的折叠?
- intellij-idea - 如何通过操作访问自定义 ToolWindow 内的组件?