I’m working on a website, and I’m having trouble with the positioning of the footer. I want the footer to stay at the bottom of the page, but it’s not working as expected.
Here’s the relevant part of my CSS code for the footer:
footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
background-color: black;
color: #fff;
padding: 10px 0;
font-size: small;
display: flex;
flex-direction: column;
align-items: center;
}
here’s the relevant part of my HTML code for the footer:
<footer >
<div class="footer-content">
<p>©2023 All rights reserved | This website is made with ♥ by XXXXXX.</p>
</div>
</footer>
I realized my footer tag was outside the body tag in my HTML code. I fixed it but still having this issue. I also checked my CSS to ensure that no other styles are conflicting styles or elements in my HTML that might affect the position.
2
Answers
I don’t know how your header is positioned (if you have one as a component) but you c an try to do position absolute on the header and group the body and footer together. Ultimately you’ll be arranging all your pages the same way as well. Example: (root folder/pages folder/index.js) is actually rendering (root folder/pages folder/components/index.js). Naming convention isn’t important, naming them same just makes it easier to track. Your (root folder/pages folder/components/index.js) would look somewhat like this:
export default Index;
This then gives you liberty to position them however you want.