Material UI Paper component does not extend to full viewport height

My React component includes a Material UI <Paper> component that acts as a background. This <Paper> is nested inside a <ThemeProvider>, which in turn is nested within a <div>, and then further nested inside the <body>. I have set the attribute to viewport: 100vh to make it take up the entire height of the screen. Initially, it does fill the full height, but once another <Paper> component is rendered on the right side, the bottom of the original paper no longer extends to the bottom of the screen: https://i.sstatic.net/KtX4s.png

This is how the App render method begins:

return (
    <ThemeProvider theme={theme}>
      <Paper style={{ height: '100vh', boxShadow: 'none' }}>
        <Container fluid id='app'>
        .......
)

I attempted applying the viewport: 100vh attribute to both the wrapping <div> in index.js and the <body> element in index.html, but saw no difference. It's worth noting that I am currently using react-bootstrap Containers/Rows/Cols for my grid system (yet to switch to Material UI), but they are all nested within the <Paper>, so I don't believe they are causing the issue. Removing any applied css on the <Container> also did not resolve the problem.

The <ThemeProvider> is using a muiTheme:

export default function createTheme(isDarkModeEnabled) {
    return createMuiTheme({
        palette: { 
            type: isDarkModeEnabled ? 'dark' : 'light',
            primary: {
                main: '#6DD3CE',
                dark: '#639FAB'
            },
            secondary: {
                main: '#52CBC5'
            }
        },
        typography: {
            fontFamily: [ 'montserratlight', 'Times New Roman' ].join(','),
            body2: {
                fontFamily: [ 'montserratmedium', 'Times New Roman' ].join(',')
            },
            h3: {
                fontSize: '1.75rem'
            },
            button: {
                fontFamily: [ 'montserratmedium', 'Times New Roman' ].join(',')
            }
        }
    })
}

Update and Solution

I opted to redesign my layout using flexbox instead of react-bootstrap, and managed to resolve the issue by changing from height: 100vh to min-height: 100vh for the container, allowing it to expand accordingly.

Answer №1

It seems like the <Container> in your code has some padding causing the content to exceed its height:

https://i.sstatic.net/iqTlX.png

This issue may also be related to the <textarea /> not having a specified height, especially on medium-sized screens.

If you're considering moving away from Bootstrap's layout system, you could explore using flexbox and styled containers instead:

import React from "react";
import styled from "styled-components";

export default function App() {
  return (
    <Container>
      <StyledHeader>Hello StackOverflow</StyledHeader>
      <StyledCol>
        <p>This is column 1.</p>
      </StyledCol>
      <StyledCol>
        <p>This is another column.</p>
      </StyledCol>
    </Container>
  );
}

const Container = styled.div`
  height: 700px;
  width: 100%;
  display: flex;
  flex-flow: row wrap;
  justify-content: space-between;
`;

const StyledHeader = styled.h1`
  height: 30%;
  width: 100%;
  margin: 0;

  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
`;

const StyledCol = styled.div`

  height: 70%;
  width: 50%;
  & p {
    text-align: center;
  }

`;

Check out this example on CodeSandbox: https://codesandbox.io/s/stack-63802170-flexbox-example-909ol

Using this approach will allow for greater control over the page layout.

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

Can you please provide the CSS code that would style this table in a similar manner?

I am interested in utilizing the design of this table, but how can I update it to meet CSS standards and HTML5 equivalents? <html> <head></head> <body> <table border="1" bordercolor="#000000" style="background-color:#ffffff" w ...

Is there a way to modify the appearance of blocks in Scratch/Blockly?

I am currently working on customizing the appearance of the blocks in Scratch by looking into adjusting the GitHub repository of scratch-blocks (https://github.com/LLK/scratch-blocks). There is a chance that I might need to modify the GitHub repository of ...

Adjust the Highcharts semi-pie design by eliminating the gap between the pie and the legend

I'm having trouble adjusting the spacing between the bottom of a semi circle donut chart in Highcharts and the legend below it. Despite my efforts, I have not been successful in reducing this gap. Here is the basic chart I am currently working on: h ...

Encountering issues while deploying Heroku with React and Next.js

After successfully running my react/next js app with no errors or warnings on my localhost, I encountered deployment issues on Heroku. Each time I try to deploy, I consistently receive an error indicating that the posts array (in pages/landing.js) is undef ...

Attempting to modify the background color of an iFrame in Internet Explorer

I am experiencing an issue with my webpage where the iFrame is displaying with a white background in IE, while it shows up with a blue background in Firefox and Chrome. I have attempted various solutions to make the background of the iframe blue or transpa ...

tips for creating a mobile-friendly responsive button

I have been scouring the internet for a solution to this issue. Essentially, I am trying to position the button on the right side in desktop view. Here is an example: chrome view However, when the site is resized or viewed on mobile devices, the button sh ...

What is the best way to apply background color to match the height of the parent element?

When creating cards, I encounter a challenging issue. I am struggling to fill the background-color of the entire box content as I am new to HTML and CSS and unsure how to achieve this. Below are my codes. .box-container1 { display: flex; justify-con ...

Ensure that Google Tag Manager (GTM) delays the pageview until the SPA URL title is available

I'm dealing with a React SPA that manages all the URL titles on the frontend, so the historyChange event registered on GTM captures the visited URLs along with their titles correctly. However, I've noticed that on the initial load of the SPA, su ...

The React application is functioning properly; however, during compilation, it continually displays an error stating that the module cannot be found

Compilation Failed. Error: Module not found, unable to resolve the specified path. webpack compiled with 1 error I was hoping for a successful compilation, but unfortunately encountered an error. It's perplexing as the application is functioning co ...

Customize the appearance of the date input box in MUI KeyboardDatePicker

Currently, I am attempting to customize the appearance of the KeyboardDatePicker component including board color, size, font, and padding. However, none of the methods I have tried seem to be effective. Here is what I have attempted so far: 1 . Utilizing ...

"Utilizing the usePrevious hook in React: A step-by-step

After referencing the React documentation, it seems like I may not be using this code correctly. import { useEffect, useRef } from 'react'; export default function usePreviousState(state) { const ref = useRef(); useEffect(() => { ref ...

Have you ever wondered how to disable a tooltip in React Material UI after clicking on it? Let

I am working with a Material-UI tab component and I would like to include a tooltip feature. The issue I am facing is that the tooltip does not disappear when I click on the tab. It should hide after clicking on the tab. Currently, the tooltip remains vi ...

Leveraging the boolean values of attributes within JSX statements

I have been working on a React.js project where I am trying to incorporate a data-picker plugin that requires a specific style of input-attributes: <input data-enable-time=true /> However, I have encountered an issue where webpack fails to compile t ...

Tips for preloading images in Gatsby

Is there a way to preload images in Gatsby before displaying the page to users without using the default preload effect? I'm also trying to figure out how to force images that are not visible to preload, as this is a significant challenge I am facing ...

What is the best way to retrieve a style property from a <style> tag using JavaScript?

Is there a way to retrieve CSS properties set in the <style> tag in JavaScript, rather than just those set in the element's style attribute? For example: <style> div{background:red;} </style> How can I access these styles, such ...

Impossible to create margins on both the left and right side

Check out this cool pen: http://codepen.io/helloworld/pen/BcjCJ?editors=110 I'm facing an issue where I'm unable to create both left and right margins around my datagrid. Only the left margin seems to be possible. Any suggestions on how I can f ...

What could be causing a momentary 404 error when I click on a next.js `Link` that connects to an API endpoint before redirecting to the intended page?

Hello there, I recently followed a tutorial on adding authentication with Passport to Next.js from this resource: https://auth0.com/blog/next-js-authentication-tutorial/ However, I encountered a minor issue. When I click the "/login" Link in my Next.js ...

What is the best way to ensure input text fills the entire grid?

Take a look at this code snippet: <div class="form-group col-md-6"> <label class="col-md-4">Last Updated (Real Time)</label> <input class="form-control col-md-8" type="text" ng-model="status.lastUpdated" ng-readonly="true"/ ...

Creating .html pages for dynamic routes in a Next.js application

Having a Next.js app (version 13.4.5) with a dynamic route /blog/[slug], I am looking to export the app as a static website. The directory structure is as follows: /app /blog /[slug] page.jsx page.jsx layout.jsx globals.css ... The n ...

Using a Do/While loop in combination with the setTimeout function to create an infinite loop

Having trouble with this script. The opacity transition works fine, but there seems to be an issue with the loop causing it to run indefinitely. My goal is to change the z-index once the opacity reaches 0. HTML <div class="ribbon_services_body" id="ri ...