css 如何让页脚粘在页面底部?[复制]

mxg2im7a  于 2024-01-09  发布在  其他
关注(0)|答案(2)|浏览(157)

此问题在此处已有答案

How do you get the footer to stay at the bottom of a Web page?(32个回答)
3天前关闭。
由于某种原因,它只在主页上工作。有什么建议吗?还有一件事,网站在这里:https://captainsapphire.github.io/(现在忽略其他问题)。

  1. #footer-container {
  2. align-items: center;
  3. justify-content: center;
  4. }
  5. footer {
  6. background-color: #1D3557;
  7. color: #E63946;
  8. position: absolute;
  9. margin-bottom: 0;
  10. width: 100%;
  11. height: 4rem;
  12. }
  13. footer address {
  14. float: left;
  15. padding-top: 2%;
  16. padding-right: 2%;
  17. }
  18. #footer-image {
  19. width: 40px;
  20. height: 40px;
  21. float: right;
  22. padding-top: 2%;
  23. padding-right: 2%;
  24. }

个字符

guykilcj

guykilcj1#

我看到你的代码,如果你添加 bottom:0 px;position:fixed; 到页脚样式,你的页脚将粘在页面的底部。

  1. #footer-container {
  2. align-items: center;
  3. justify-content: center;
  4. }
  5. footer {
  6. background-color: #1D3557;
  7. color: #E63946;
  8. position: absolute;
  9. margin-bottom: 0;
  10. width: 100%;
  11. height: 4rem;
  12. position: fixed;
  13. bottom: 0px;
  14. }
  15. footer address {
  16. float: left;
  17. padding-top: 2%;
  18. padding-right: 2%;
  19. }
  20. #footer-image {
  21. width: 40px;
  22. height: 40px;
  23. float: right;
  24. padding-top: 2%;
  25. padding-right: 2%;
  26. }

个字符

展开查看全部
pgx2nnw8

pgx2nnw82#

这应该会有所帮助,我从**#footer-container**中删除了position: absolute,并添加了margin-top: auto将其推到底部,并编辑了一些填充值。

  1. #footer-container {
  2. display: flex;
  3. align-items: center;
  4. justify-content: space-between;
  5. background-color: #1D3557;
  6. color: #E63946;
  7. height: 4rem;
  8. width: 100%;
  9. margin-top: auto;
  10. }
  11. footer address {
  12. padding-top: 2%;
  13. padding-left: 2%;
  14. }
  15. #footer-image {
  16. width: 40px;
  17. height: 40px;
  18. padding-right: 2%;
  19. }

个字符

展开查看全部

相关问题