'How do I push the footer to the bottom of the page?
I don't have any space under my footer in the desktop as well as the mobile versions with the exception of the iPhone X and the iPad. I've messed around with media, calc(100vh - height) overflow, position etc., but nothing seems to be working. I read one suggestion that was to put all the content into a container and then set the footer to position: absolute, but I'm not sure how that will affect my grid.
body {
line-height: 1;
background-color: #f3f3f3;
}
.services-wrapper {
display: grid;
width: auto;
grid-template-rows: auto 3fr;
grid-row-gap: 20px;
height: calc(100vh - 30px);
}
.services-grid {
padding-bottom: 30px;
overflow: auto;
}
.services-grid>div {
background-color: white;
vertical-align: middle;
padding: 25px;
margin: 30px;
}
footer {
position: relative;
padding-top: 5px;
margin-top: -30px;
background-color: white;
height: 30px;
width: 100%;
overflow: hidden;
clear: both;
}
<header></header>
<main>
<section class="services-banner">
<div class="services-vertical-center">
</div>
</section>
<section class="services-grid-wrapper">
<div class="services-grid">
<div class="services-grid-desc">
</div>
<div class="services-grid-desc">
</div>
<div class="services-grid-desc">
</div>
</div>
</section>
</main>
<footer></footer>
Solution 1:[1]
You can try setting the body to be flex.
Also it helps setting the html and body to have a min height of the window height.
html, body {
min-height: 100vh;
}
body {
display: flex;
flex-direction: column;
}
footer {
margin-top: auto;
}
Solution 2:[2]
I think you are looking for something like this:
html, div, header, nav, section,
time, mark, audio, video {
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
footer,header,nav,section {
display:block;
}
.services-wrapper {
display: grid;
width: auto;
grid-template-rows: auto 3fr;
grid-row-gap: 20px;
height: calc(100vh - 30px);
}
.services-grid {
padding-bottom: 30px;
overflow: auto;
}
.services-grid > div {
background-color: white;
vertical-align: middle;
padding: 25px;
margin: 30px;
}
body{
background-color:rgb(39, 39, 39);
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: black;
color: white;
text-align: center;
padding: 17px;
}
a{
padding: 20px;
font-size: 18px;
color:white;
text-decoration:none;
}
<body>
<header>
</header>
<main>
<section class="services-banner">
<div class="services-vertical-center">
</div>
</section>
<section class="services-grid-wrapper">
<div class="services-grid">
<div class="services-grid-desc">
</div>
<div class="services-grid-desc">
</div>
<div class="services-grid-desc">
</div>
</div>
</section>
</main>
<div class="footer">
<a href="">Terms
</a>
<a href="">Privacy policy</a>
<a href="">About</a>
<a href="">Contact Us</a>
</div>
</body>
Let me know if it helps you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SebastianOpperman |
| Solution 2 | HelloWorld.exe |
