Ensuring the footer stays anchored at the bottom using Material-UI Expansion Drawers

Utilizing Material-UI@next in my React application, I have a component that showcases a list of items using Expansion Panels. Additionally, there is a straightforward <Footer /> component structured like this:

import React, { Component } from "react";

import styled from "styled-components";
import Typography from "material-ui/Typography";

const FooterContainer = styled.div`
  text-align: center;
  position: absolute;
  bottom: 0;
  width: 100% !important;
  height: 100px !important ;
  background: #6cf;
`;

class Footer extends Component {
  render() {
    return (
      <FooterContainer>
        <Typography variant="title">Footer Text</Typography>
      </FooterContainer>
    );
  }
}

export default Footer;

This part of the code snippet features the usage of <Footer /> beneath the list of items:

  render() {
    return this.props.isFetching ? (
      <Typography>Loading...</Typography>
    ) : (
      <Container>
        <StyledTitle variant="display1" gutterBottom color="secondary">
          Listings
        </StyledTitle>
        <Grid container spacing={24}>
          {this.renderListings()}
        </Grid>
        <Footer />
      </Container>
    );
  }

In this block, the function renderListings() iterates over an array and presents the outcomes within an Expansion Panel:

...
      <Grid key={listing._id} item xs={12} sm={12} lg={12}>
        <StyledExpansionPanel>
          <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
            <ExpansionPanelColumn>
              <Typography>{listing.name}</Typography>
            </ExpansionPanelColumn>
          </ExpansionPanelSummary>
          <Divider />
          <ExpansionPanelDetails>
            <Typography>Notes: {listing.notes}</Typography>
          </ExpansionPanelDetails>
          <Divider />
        </StyledExpansionPanel>
      </Grid>
...

The issue arises when the Expansion Panels are expanded, causing them to overlap with the footer instead of staying at the bottom of the page.

Answer №1

I came up with a solution using flex. Basically, all I had to do was adjust the style of the <Container /> component like this:

export const Container = styled.div`
  display: flex;
  min-height: 100vh;
  flex-direction: column;
`;

By wrapping the vertical sections in a flex container and specifying which ones should expand, they automatically fill up all available space within their container.

Answer №2

footer {
  margin-top:calc(5% + 60px);
  bottom: 0;
}

It's been working perfectly for me!

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

Unexpected data displayed in React list after item deletion issue

I am currently working with a basic list of student objects that include their names and scores in the state. The name is displayed using <b>{student.name}</b>, while the score is displayed using <input type="text" defaultValue={s ...

Is there a way to retrieve the left offset of a floating element even when it is positioned outside the viewport?

My current situation involves creating several panels that are stacked side by side within a main container. Each panel takes up 100% of the viewport width and height. I want to be able to horizontally scroll to each panel when clicking on their respective ...

The resizing effect in jQuery causes a blinking animation

I would like to create a functionality where, when the width of .tabla_gs_gm surpasses the width of .content, .tabla_gs_gm disappears and another div appears in its place. While this is already working, there seems to be a screen flicker between the two d ...

I seem to be encountering a z-index dilemma

Is there a way to make my slogan float above an image on a wide screen? I've tried adjusting the z-index without success. You can find the site here: Here is the CSS code: The #Slogan contains the words: Fitness Bike Guides - Top Models - Discount ...

Unexpected behavior with first-child selector in a simple CSS code

It seemed so clear to me, but it turns out I was mistaken. Check out this link $('p:first-child').css({color:'red'}); The color of all text is not being altered. <div class="post text"> <a href="#">this is a url</a> ...

Prevent clicking through slides on React by disabling the Swiper feature

Is there a way to handle the global document click event (using React hook useClickAway) so that it still fires even when clicking on a slide? For example, think of a circle in the header like an avatar dropdown - when you click on it, a menu pops up. Th ...

The overflow:hidden feature is ineffective in Firefox, yet functions properly in both IE and Chrome browsers

I'm in the process of creating a webshop and facing an issue with my sidebar due to varying product counts on different pages. For now, I have implemented the following workaround: padding-bottom: 5000px; margin-bottom: -5000px; overflow: ...

When encountering error code EINTEGRITY during npm installation, a warning about a potentially corrupted tarball may be displayed

I have been facing an issue for the last three days with my react+vite project on Windows 10. Whenever I attempt to install dependencies using npm install, I encounter the following error: npm WARN tarball tarball data for fast-levenshtein@https://registry ...

Clearing input after submission in React can be achieved by setting the input value

Is there a way to reset the input field in this code after submitting with the button? export default function Form({addTask}) { const [taskInp, setTaskInp] = useState("") return ( <div> <input type="text&quo ...

Leveraging NextJS to preload Redux data with getServerSideProps

After reviewing the information in the official NextJS docs, it is recommended to utilize getServerSidedProps and getStaticProps rather than getInitialProps. The goal is to preload some data into the Redux state on the server side. Note: I am implementin ...

Tips for fixing the error 'deletePerson is not defined' in a react js onClick event

This is the AppComponent, which serves as the container component for functions: import React, { Component } from 'react'; import './App.css'; import MainComponent from './MainComponent/MainComponent'; import AddPerson from ...

React component not accurately substituting function with Sinon stub

I'm currently experimenting with testing a click on a React component using Enzyme and Sinon. var stub = sinon.stub(Comp.prototype, 'save', function() { }); let wrapper = shallow( <Comp/> ); wrapper.find('.btn-header' ...

Trouble with getting Tailwind CSS animations to function properly in ReactJs/NextJs

Recently, I delved into learning Tailwind and Nextjs by following a tutorial step by step. One interesting thing I encountered was trying to implement a bounce animation on an icon when it's hovered over. Surprisingly, it worked perfectly the first ti ...

Is it possible to enhance a form box with a border?

Having trouble adding a border to my bootstrap form box. I've tried applying border style properties but it doesn't seem to be working. Any suggestions? This is the class for the form box: <div class="form-box"> <div ...

generate a dropdown menu within a CSV file using JavaScript

Currently, I am working on exporting a CSV file in Reactjs and facing an issue with creating a dropdown in the generated CSV file. I have attempted using plugins like excel.js, shell.js, as well as csvlink download. <CSVLink data={data}>Download me ...

React app running on Docker does not need to recompile code

I've been working on containerizing a basic Create-React-App template using Docker. The Dockerfile I'm using looks like this: FROM node:latest WORKDIR /usr/src/client COPY ./ ./ RUN npm install EXPOSE 3000 CMD ["npm", "start"] After buildin ...

Minimize the entire project by compressing the .css, .js, and .html files

After recently incorporating Grunt into my workflow, I was thrilled with how it streamlined the process of minifying/concatenating .css files and minifying/uglify/concatenating .js files. With Grunt watch and express, I was able to automate compiling and ...

Require a selection from the menu on the right side needed

I am looking to have the logout link displayed on the far right when the other menu items are hidden. Currently, it is appearing in the center. Is there a way I can make it show up on the right? <div class="nav-content container"> &l ...

Transforming the hue of a radio-button

When it comes to the default CSS code for radio buttons, they appear gray when unselected and blue when selected: https://i.stack.imgur.com/hsazr.png However, I have a specific requirement for them to be black in both states. In order to achieve this, I ...

What is the best way to incorporate padding into an Angular mat tooltip?

I've been attempting to enhance the appearance of the tooltip dialog window by adding padding. While adjusting the width and background color was successful, I'm encountering difficulties when it comes to styling the padding: https://i.sstatic.ne ...