Reputation: 122
I am trying to make a simple landing page. I went for minimalistic look and made a simple land page. But while trying to add a footer, it overlaps my content that I have aligned to center. I made an exactly same code on codepen.io please view it there or use the code provided below.
My HTML:
<body>
<h1>Some Header</h1>
<div class="main-land-container">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing eli</p>
<input placeholder="Lorem"></input>
<input type="submit" placeholder="submit"> </input>
<input type="date"></input>
</div>
<footer>
<h3>Some sample footer</h3>
</footer>
</body>
My css:
body {
background-color: #24292e;
}
h1 {
text-align: center;
}
h1, h2, h3 {
color: white;
}
p {
color: yellow;
}
input {
margin: 2em;
}
/*-------Below is the code that causes the problem*/
.main-land-container {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.3); /* For card */
transition: 0.3s;
display: flex;
flex-direction: column;
justify-content: space-between;
margin-top: 1em;
position: absolute; /*For centering */
left: 50%;
transform: translate(-50%, 0%);
text-align: center;
}
.main-land-container:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.5);
}
.main-land-items {
margin: 2em;
}
footer {
background-color: red; /*For debugging*/
position: fixed;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
color: #ffffff;
}
/*I can edit the footer and the main-land-container as long as it looks like what it is now. All I want is my footer to stay at bottom without overlapping my content in the card.*/
It works very nice on laptops or dekstop. But if I open it on my phone, or resize it, or opened a keyboard to type on my phone, the footer is dragged up and overlaps my content.
Heres if I scaled my device to mobile:
The thing is, the card cant be even scrolled to the bottom if I use mobile. The footer overlaps the card.
Thank you for helping. Please comment if any more info is needed.
Upvotes: 1
Views: 62
Reputation: 601
Initially, you must remove position fixed (and other rules related to position) for footer. That rule will be look just simpler:
footer {
color: #ffffff;
}
Then use follow code for body:
body {
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
}
Another way: just add to div .main-land-container
property margin-bottom with value equal to footer height in pixels.
Upvotes: 1
Reputation: 94
I think your content is less, which is not scrollable due to fixed footer, so you must remove fixed footer
Upvotes: 0