In my site, I have to create a policy banner.
My site already contains div for content and footer.
What I want?
- I want to set this banner in a way that it will stick to user's view port bottom (note: it shouldn't be at the page bottom but it should stay at user's display bottom).
- When user scroll through page, banner should stick at the bottom with scrolling, and that should stop when footer comes.
- Footer will remain at the end of page.
now, most of things I have achieved but issue is to keep footer at bottom and banner Scrolling should stop above footer.
My example code:
.main-area {
height: 1000vh;
background-color: #ccc;
width: 2000px;
position: relative;
}
.policy-banner {
height: 100px;
width: 2000px;
color: yellow;
background-color: blue;
position: fixed;
bottom: 0;
left: 0;
}
.footer {
background-color: black;
height: 50px;
color: white;
position: fixed;
bottom: 0;
left: 0;
}
<html>
<head>
</head>
<body>
<div class="main-area">
<section>another sections coming dynamically</section>
<section>another sections coming dynamically</section>
<div class="policy-banner">
this is banner, it should stick to the user's view port.
when user scroll, it will also scroll but upto footer and should not overlap with footer.
</div>
</div>
<footer class="footer">
this is footer. it will stay at the end of the page.
</footer>
</body>
</html>
Any help would be really appreciated. thanks.
Edit: This is not duplicate question as what I wanted is css solution and this marked answer solved my issue with sticky banner.