Creating a Footer with React and Material-UI: Step-by-step Tutorial

I'm facing an issue with the footer on my webpage. Here are my requirements:

  • It should always be positioned at the bottom after the page content
  • If there isn't enough content to fill the page, it should still stick to the bottom of the screen
  • I am currently working with React and Material UI https://i.sstatic.net/TVOWXsJj.png

Some resources suggest using the footer height as a buffer, but that involves hardcoding the height (like in this guide).

I've also tried implementing flexbox as per some tutorials, but I seem to struggle getting it to work within a React environment. I attempted to replicate this example.

Here's a snippet of the code:

import type { Metadata } from "next";

import "./globals.css";

import { AppRouterCacheProvider } from "@mui/material-nextjs/v13-appRouter";
import Box from "@mui/material/Box";
import { AppBar, Typography } from "@mui/material";

export const metadata: Metadata = {
  title: "Footer example",
  description: "How can footers be hard?"
};

export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
  return (
    <html lang="en">
      <body>
        <AppRouterCacheProvider>
          <Box
            sx={{
              height: "100%",
              display: "flex",
              flexDirection: "column"
            }}
          >
            <AppBar sx={{ height: "80px" }} />
            <Box
              sx={{
                flexGrow: 1,
                flexShrink: 0,
                flexBasis: "auto"
              }}
            >
              {children}
            </Box>
            <Box
              sx={{
                backgroundColor: "lightblue",
                flexShrink: 0
              }}
            >
              <Typography>Example footer!</Typography>
            </Box>
          </Box>
        </AppRouterCacheProvider>
      </body>
    </html>
  );
}

Can someone help me identify what might be causing the issue?

Answer №1

If you're looking to ensure your footer stays at the bottom of the page, a simple adjustment can be made. By adding minHeight: 100vh to your flexbox styling, you can achieve this layout.

 <Box sx={{
    minHeight: "100vh",
    display: "flex",
    flexDirection: "column",
  }}
>
//Your Code

Note:- Keep in mind that using 100vh may cause unnecessary scrolling in certain scenarios. Consider adjusting the height to 98vh or 99vh to prevent this issue while still maintaining the desired layout in most cases.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Animation using jQuery is functional on most browsers, however, it seems to

After creating an animation to simulate an opening door using jQuery, I discovered that it works perfectly on Firefox 24, Chrome 28, and IE 8. However, Safari presents a problem - the door opens but then the "closed" door reappears at the end of the animat ...

npm encountered an issue resolving a dependency

I've been experimenting with different solutions to update or install packages, such as removing node_modules and the package-lock file, clearing the cache. However, I keep encountering errors like the one below: npm ERR! code ERESOLVE npm ERR! ERESOL ...

I'm attempting to set up three columns that fade in responsively. Is there a way to make them appear side by side instead of stacking on top of each other?

Is there a way to display the three columns horizontally instead of vertically? I also want them to adjust responsively and fade smoothly. Here is my fiddle link: https://jsfiddle.net/Spleendrivel/dswufb78/3/ <!DOCTYPE html> <html> <head ...

What is the best way to send root parameters within the resolver function of a nested query?

I have a question regarding the structure of my GraphQL queries Category1(name: $cat1){ Category2(secondName: $cat2){ secondName }} This is how my schema is set up: const Query = new GraphQLObjectType({ name: 'Query', fields: { ...

Keep the Material UI ClickAwayListener open during touchmove events

My lack of experience with mobile touch events has led me to seek clarification on a specific issue. I have implemented a Material UI ClickAwayListener that wraps a Popper. The objective is for this Popper to remain open until the user clicks or taps outsi ...

Steps to create a navbar that spans only 75% of the header

Hello, I am currently working on a project and I am trying to deploy a navbar that looks like this: I have tried multiple CSS scenarios but I can't seem to achieve it. I explored everything in the Bootstrap documentation but couldn't find a solu ...

Extra space within table in Firefox

Experiencing an issue with excess whitespace in a table on Firefox. Visit the live example at The problem can also be seen on this jsFiddle: http://jsfiddle.net/DVbCC/ In Chrome and Safari, rows are neatly arranged with minimal spacing, but Firefox show ...

CSS - Help! Seeing different results on Internet Explorer

I'm currently handling an OSCommerce website, and I'm trying to figure out why this issue is occurring. You can view the website at this link: The layout looks completely different on Internet Explorer, and I'm puzzled as everything should ...

The z-index property does not seem to function properly when used in conjunction

I am experiencing an issue with the z-indexes of two divs: one with default positioning and the other with a fixed position. No matter how I adjust the z-index values, it appears impossible to make the fixed-positioned element go behind the statically pos ...

Create a dynamic AppBar Toolbar in React Admin that changes based on the current page

Recently delving into the world of React, I've been facing some challenges when it comes to loading IconButtons onto the toolBar of an AppBar (from Material UI). For instance, I'm looking to have two specific IconButtons displayed on pageA and d ...

Struggling to configure a React-Redux boilerplate

I encountered an issue with my previous boilerplate while working on a project, so I decided to switch to a different one. After exploring Github, I came across this repository that seemed simple and similar to what I needed. Upon cloning it and running np ...

receiving incorrect request rather than the complete error message

Handling errors when using POST with the same user email can be achieved using the following code snippet (utilizing superagent): export function signUpUser(userData) { return async dispatch => { try { const currentUser = await request.pos ...

Is there a way to maintain the original indexing of a list after users have selected a filtered item in React using Webpack?

After implementing a filter (filteredCat) for my catalogue, the visual display works as expected. One issue I am facing is that even though the items are filtered, the logged index does not correspond to the new filtered list but instead reflects the inde ...

Display an image when the cursor hovers over a text

I'm attempting to display an image when hovering over specific text. The image should not replace the text, but appear in a different location. The concept is as follows: When hovering over the word "Google", the Google logo should appear in the red ...

Beginner experiencing website overflow problem

After completing a basic web development course, I decided to create my first homepage. While I am satisfied with how it looks on a PC or laptop, the layout gets messy on mobile devices. I tried using <meta name="viewport" content="width= ...

Looking for a basic image/div slider that works smoothly with ie9?

Can anyone recommend a basic content slider that is compatible with IE9? ...

Efficiently Organizing Data Using Coldfusion Loops in Columns and Rows

My issue lies in pulling data from a database to display on my website. I have three keys/attributes (columns) - PostedDate, DataImage, and Source that need to be shown together in one div with the posted date at the top, image in the middle, and source at ...

Personalize scrollbar appearance in Mozilla Firefox and Internet Explorer

When it comes to customizing the scrollbar in chrome, CSS makes it easy: ::-webkit-scrollbar { width: 7px; } Unfortunately, this method does not have the same result in Firefox (version 38) and IE (version 11). I attempted the following code as an alter ...

Enhance your input text form with a stylish button using Bootstrap

This is the code snippet I am currently working on: <h2>Workout Selector</h1> <div class="form-group"> <label for="workout-name">Search by Keywords (Comma Separated):</label> <input ...

Can you show me the procedure for retrieving a particular element with selenium? (Page Source provided)

Disclaimer: I must admit that my knowledge of HTML and CSS is minimal, so please bear with me! Hello everyone, I am attempting to utilize selenium[Java] to browse a website and retrieve a file. While I managed to successfully get past the login page, I fi ...