Next.js Discord

Discord Forum

Website footer is overlapping/blocking main content

Answered
Cordilleran Flycatcher posted this in #help-forum
Open in Discord
Cordilleran FlycatcherOP
I am using Next.js with the app directory.

Here is my code in footer.js.
"use client"
import React from 'react';
import Typography from '@mui/material/Typography';
import styles from './footer.module.css';

const Footer = () => (
    <footer className={styles.footer}>
        <Typography color = "white" variant = "body2" gutterBottom component = "div" align = "center" style = {{margin: "10px"}}>
            <a style = {{color:'yellow'}} href = "https://google.com" rel = "noreferrer" target = "_blank">I like Google</a><br /> I am a college student
        </Typography>
    </footer>
);

export default Footer;


And here is my footer.module.css code.
.footer {
    bottom: 0;
    left: 0;
    right: 0;
    position: fixed;
    z-index: 9999;
    background-color: #000000;
}

Whenever I import the footer component into a page.js file and insert it at the bottom of the return statement, I notice that the footer overlaps content in that page.

Here is a screenshot of the bottom of a page with the footer (I removed the text in the footer after taking the screenshot). See first screenshot.

And here is a screenshot off the bottom of that same page without the footer. See the second screenshot.

You can see that the pagination/navigation bar at the bottom is hidden inside the footer. How do I ensure this doesn't happen? I'd ideally like the footer to be stuck to the bottom of the page no matter what. If the user has to scroll, that's fine, but the header and footer should always be visible.
Answered by Cordilleran Flycatcher
Figured out a solution. I am using the mui library in my project. I just updated the bottom navigation component to act as a footer. 🙂
View full answer

17 Replies

@Cordilleran Flycatcher I am using Next.js with the app directory. Here is my code in `footer.js`. js "use client" import React from 'react'; import Typography from '@mui/material/Typography'; import styles from './footer.module.css'; const Footer = () => ( <footer className={styles.footer}> <Typography color = "white" variant = "body2" gutterBottom component = "div" align = "center" style = {{margin: "10px"}}> <a style = {{color:'yellow'}} href = "https://google.com" rel = "noreferrer" target = "_blank">I like Google</a><br /> I am a college student </Typography> </footer> ); export default Footer; And here is my `footer.module.css` code. css .footer { bottom: 0; left: 0; right: 0; position: fixed; z-index: 9999; background-color: #000000; } Whenever I import the footer component into a `page.js` file and insert it at the bottom of the return statement, I notice that the footer overlaps content in that page. Here is a screenshot of the bottom of a page with the footer (I removed the text in the footer after taking the screenshot). See first screenshot. And here is a screenshot off the bottom of that same page without the footer. See the second screenshot. You can see that the pagination/navigation bar at the bottom is hidden inside the footer. How do I ensure this doesn't happen? I'd ideally like the footer to be stuck to the bottom of the page no matter what. If the user has to scroll, that's fine, but the header and footer should always be visible.
where are you mounting the footer?
@@ts-ignore where are you mounting the footer?
Cordilleran FlycatcherOP
At the bottom of the page
Cordilleran FlycatcherOP
For some reason, I am not able to copy and paste the code here so here is a file. it is for the same page as the one in the screenshots
@@ts-ignore add the footer in `layout.tsx`
Cordilleran FlycatcherOP
That doesn't fix the issue. The bottom part of my page is still hidden underneath the footer.
Here is my globals.css file
@@ts-ignore remove the position:fixed
Cordilleran FlycatcherOP
That works, but the footer is only visible when the user scrolls all the way to the bottom of the page. I want the footer to always be visible. And if I have a page that doesn't take up the whole screen, the footer isn't shown at the very bottom, but right beneath all other content. Here is the bottom of my website homepage. Notice all the whitespace underneath the footer. Not to mention the footer doesn't even take up the full width.
@@ts-ignore if you want to show it every time like it was before then you will have to add some padding to your content because it was under the content
Cordilleran FlycatcherOP
That doesn't fix the issue. Also, I can't put the footer in layout.js because I have some pages/components that should not show the footer. I need to manually add it to each page
@@ts-ignore then add some margin top to the footer
Cordilleran FlycatcherOP
From my testing, it seems like setting the position to fixed in the footer.module.css file is the only way to make the footer always visible. Adding margins keeps the footer in one place, but not the very bottom of the page. The footer is now in the middle of the page always
otherwise you're going to have to just place the Footer component in each page one-by-one
@Ichneumonid wasp otherwise you're going to have to just place the Footer component in each page one-by-one
Cordilleran FlycatcherOP
That is what I am doing. Not a lot of pages so not too tedious.
Cordilleran FlycatcherOP
Figured out a solution. I am using the mui library in my project. I just updated the bottom navigation component to act as a footer. 🙂
Answer