html - Sticky footer with background image
问题描述
I have a footer in the body which is supposed to be tacked onto the bottom of the page (not fixed and always on the page). I think this is a called a sticky footer. It seems to only occur on pages where the content on the page does not span very far vertically. However on some pages there is a gap of whitespace below the footer like so:
I have made the background orange so you can see where the footer is on this page.
On another page, it looks like this (correctly:
I'm wondering how I could fix this, or if there would be a better way to design the footer - I did not write it originally.
Here is the html which is within a body element:
<footer class="main-footer">
<div class="container">
<ul class="links">
<li><a href="link1">stuff1</a></li>
<li><a href="link2">stuff2</a></li>
<li><a href="link3">stuff3</a></li>
<li><a href="link4">stuff4</a></li>
</ul>
</div>
</footer>
Note that the body is rendered with @RenderBody()
with the footer following after.
and here is the CSS:
.main-footer {
background-image: url("images/footer-background.png");
background-size: cover;
background-position: initial;
background-repeat: no-repeat;
background-color: #ffffff;
z-index: 10;
padding-top: 2%;
left: 0;
color: #fff;
text-align: right;
height:190px;
bottom:0;
}
.main-footer .links {
padding: 0;
margin-top: 100px;
list-style: none; }
.main-footer .links li {
display: inline-block; }
@media only screen and (max-width: 768px) {
.main-footer .links li {
display: block;
margin-bottom: 5px; } }
.main-footer .links li:not(:last-child) {
margin-right: 15px; }
.main-footer a {
color: inherit;
font-weight: 200; }
.main-footer.logged-in {
position: static;
background: #fff;
padding: 30px 0;
border-top: 1px solid #D8D8D8; }
@media only screen and (max-width: 1040px) {
.main-footer.logged-in {
margin-top: 0; } }
.main-footer.logged-in a, .main-footer.logged-in * {
color: #999999; }
.main-footer.logged-out {
position: static;
background: #fff;
padding: 30px 0;
border-top: 1px solid #D8D8D8; }
@media only screen and (max-width: 1040px) {
.main-footer.logged-out {
margin-top: 0; } }
.main-footer.logged-out a, .main-footer.logged-in * {
color: #999999; }
body.content-tall .main-footer {
position: relative;
bottom: auto;
margin-top: 30px; }
I am happy to provide more information if it would help
EDIT: I have narrowed it down to the margin-top
in:
.main-footer .links {
padding: 0;
margin-top: 100px;
which is causing the problem. However, I cannot remove the top margin since it is necessary for formatting text vertically on the page (not shown in screenshot). I have tried overflow: auto;
here which hasn't fixed it.
解决方案
.main-footer.logged-in
并.main-footer.logged-out
在顶部和底部有 30 像素的填充。不能肯定地说这是否与您的问题有关,肯定要找到我需要查看您的网站的罪魁祸首。
推荐阅读
- tomcat - 使用 Tomcat 进行家庭服务器组织
- r - 如何将手段添加到 ggplot + geom_point 图
- opencart2.x - UPS 错误:250003 访问许可证号无效
- .net - 将 Azure AD 与 Active Directory PrincipalContext.ValidateCredentials 一起使用
- solr - Solr 中的模糊字符串匹配和词频
- python - 使用 selenium 和 bs4 进行网页抓取
- bind - 夏令时对 BIND9 有什么影响?
- angular - 如何从我们从 Angular 6 中的 API 获得的响应中获取字段
- java - java如何在内部将任何类型的文件(图像、pdf等)转换为字节数组?
- ag-grid - 访问 ag-grid 列可见性事件完成