Footer not sticking to the bottom of the page with Material UI

View Page Screenshot

My challenge is with the Footer using AppBar when there is no content. It doesn't properly go to the end of the page, only to the end of the content. I want it to stick to the bottom of the page if the content doesn't reach the bottom of the screen. However, if the content extends past the screen, then I want the Footer to be at the bottom of that extended content.

Currently, the Footer is correctly positioned at the bottom of the content when it extends past the screen. But when the content doesn't reach the bottom of the screen, the Footer does not stick to the bottom of the page as desired.

const Footer = () => {
    return (
        <AppBar position='sticky' sx={{ top: 'auto', bottom: 0 }}>
            <Grid container direction='column'>
                <Grid item container>
                    <Grid item xs={0} sm={1} />
                    <Grid item xs={12} sm={10}>
                        <h1> info section</h1>
                    </Grid>
                    <Grid item xs={0} sm={1} />
                </Grid>
                <Grid item container>
                    <Grid item xs={0} sm={1} />
                    <Grid item xs={12} sm={10}>
                        <Toolbar disableGutters={true}>
                            <h1>bottom toolbar</h1>
                        </Toolbar>
                    </Grid>
                    <Grid item xs={0} sm={1} />
                </Grid>
            </Grid>
        </AppBar>
    )
}

Answer №1

One effective solution is to set the minimum height of the content area on the page, excluding the height of the header and footer. Take a look at the code provided below. Your current approach may not be the ideal solution you are seeking. Hopefully, this will clarify my suggested method.

/* General Style */
*{
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
div{
    background-color: blueviolet;
    padding: 30px;
    height: 100px;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid darkturquoise;
}
/* Styling for the solution */
.content{
    min-height: calc(100vh - 200px); /* Header + Footer = 200px */
    /*height: 800px;*/ /* Test if content extends beyond the page */
}
.footer{}
.header{}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <div class="header">Header</div>
    <div class="content">Content</div>
    <div class="footer">Footer</div>
    
</body>
</html>

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

Unleashing issues while making changes to <Route /> elements in the React front end during refactoring

Good evening, I'm new to using React and I've encountered an issue while trying to render react components after refactoring. I believe my problem is just a simple syntax error, but as a beginner, I'm struggling to figure it out on my own. ...

The issue with Internet Explorer failing to adhere to the restrictions set on maximum width and

I'm attempting to scale my images precisely using CSS: HTML: <div id="thumbnail-container"> <img src="sample-pic.jpg"/> </div> CSS: #thumbnail-container img { max-height: 230px; max-width: 200px; } In this scenario, ...

Encountering difficulties displaying navigation interface with react native navigation's stack navigator

I am trying to implement a custom side navigation bar in React Navigation without using drawerNavigator. I have fixed the side nav bar and bottom bar in app.js so that they appear on all screens. The main content area should change based on button clicks o ...

Using input masking to restrict user input to only numbers and English alphabet characters

My input field is masked as "999999999" and functions correctly with an English keyboard. However, I am able to enter Japanese/Chinese characters into it, which breaks the masking. Is there a way to limit input to English keyboard numerics only? <inpu ...

What causes delayed state updates in React/NextJS until another state is updated or a fast refresh occurs?

UPDATE: Version 13.3.0 is coming soon! In my code, I have a state variable named localArray that I need to update at a specific index. To achieve this, I decided to create a temporary array to make modifications and then set the state with the updated val ...

Arrange components within the form

Just started experimenting with this a few days ago. In my form, there is a text field and a button that I want to align side by side at the center of the form. .row { width: 100%; margin-bottom: 20px; display: flex; flex-wrap: wrap; } .col-6 { ...

Problem with implementing swipeable tabs using Material-UI in React

I'm experiencing an issue in my application with the react swipeable tabs from material-ui. I followed all the installation steps recommended in the documentation. Currently, I am encountering the error shown in the screenshot below. Could there be a ...

Having an issue with Next.js dynamic links using catch-all feature ([[...slug]]) not functioning properly when the "as" prop is used in the Link component

I have been developing a Next.js application where certain pages include in-page routes. To handle this, I have implemented a catch-all (i.e. [[...slug]]) route and managed the routing on the page itself. Here is how my folder structure looks: https://i.s ...

Unable to process form submission using Ajax in ASP.NET MVC

I'm having trouble with submitting a form using ajax and opening a modal dialog after the ajax function is successful. Whenever I click the submit button, the process doesn't complete. Where could the issue be, in the ajax method or somewhere el ...

Accessing the name attribute of the TextField component, displayed as a Select Box in Material-UI, by utilizing the event object received from the onFocus prop

Utilizing the "@material-ui/core": "4.11.2" library along with "react": "16.8.6", I've encountered an issue with the TextField component where the select prop is set to true. Specifically, I am unable to access ...

Steps for adding a row as the penultimate row in a table

There aren't many solutions out there that don't rely on jQuery, but I'm looking to avoid it. The row content needs to be generated dynamically. Here is my flawed approach: function addRow() { let newRow = '<tr><td>B ...

Steps for displaying the appended string on a web page using React hooks

Check out this code snippet: const Gauge = (props) => { const points = 100; const radius = 257; const max = 100; const peaks = [ 10, 50, 90 ]; const step = (max + 1) / points; const realPeaks = peaks.map((peak) => Math.floor(p ...

The inexplicable failure of Next.js in executing getServerSideProps

Currently, I am in the process of learning NextJS. As part of this journey, I have an API built using Laravel that features an endpoint /api/user. This endpoint is protected with a token and returns a basic user object structured as follows; { "da ...

Typescript enables bidirectional control of Swiper

I attempted to use the two-way control slider example from Swiper documentation, but I encountered TypeScript errors that prevented it from working correctly. Is there a way to make it compatible with TypeScript? The specific errors I received were: TS23 ...

Having trouble retrieving data from a JSON object in React/Redux?

It seems like there might be something obvious that I'm missing here - but I can't seem to figure out how to access the JSON data. I have a Container component: class About extends Component { componentDidMount(){ const APP_URL = 'htt ...

Troubleshoot: Inability to highlight a column and row in a table using ::after and ::before

To create a hover effect where the corresponding column and row are highlighted when the mouse is on a cell, as well as highlighting the row for player 1's actions and the column for player 2's actions, I attempted the following code: /* CSS Cod ...

Using Javascript/React to filter an array by a specific value

{ "team_group": ["Alex Smith", "Jake Brown", "Sarah King"], "group_data": { "Alex Smith": { "status": "member" }, "Jake Brown": { "status": &qu ...

Personalize the pagination or other elements of Splide in a Svelte component to suit your needs

I am currently integrating Splide into my Svelte application and facing an issue with the pagination styling. The pagination is appearing on top of my images and is too transparent for my liking. I'm utilizing Svelte Splide to incorporate this library ...

An error has occurred while adding an item to the playback queue using the Spotify API, resulting

As I was trying to achieve the functionality of immediately playing the next song after the current track ends, my approach involved using the 'add Item to playback queue' feature of the Spotify API. // WebPlayback.tsx import { useEffect, useStat ...

Pressing a shortcut key will direct the focus to the select tag with the help of Angular

I was trying to set up a key shortcut (shift + c) that would focus on the select tag in my form when pressed, similar to how tab works. Here is the HTML code for my form's select tag: <select id="myOptions"> <option selected> Opti ...