Creating two divs with equal heights in React using Material-UI at 50% each

I am currently utilizing a Material UI template within a react JS project.

My goal is to create a div (or Grid in MUI) that spans 100% of its container's height, containing two nested divs (or Grids) that are each set at 50% height. If the internal content exceeds the allocated 50%, it should be scrollable.

I have experimented with using sections but have not been successful in achieving the desired layout.

The approach I have taken so far only addresses the right column:

<Grid
        container
        direction="column"
        justifyContent="space-between"
        style={{ height: "100%" }}
      >
    <Grid item style={{ background: "red", height: "50%", overflowY: "auto" }} >
        <h1>OKKK</h1>
    </Grid>
    <Grid item style={{ background: "blue", height: "50%", overflowY: "auto" }} >
        <h1>OKKK</h1>
    </Grid>
</Grid>

This setup results in: https://i.stack.imgur.com/A8ojr.png

While this seems to work correctly for the first div where content can be added without issue, adding content to the second div causes the first div to extend beyond 50% of the total height as shown here: https://i.stack.imgur.com/olXPD.png

To address this challenge, how can I fix this layout issue?

Answer №1

Consider implementing

style={{ height: "100vh" }}
within your main element. This approach should resolve the issue at hand. To gain a deeper understanding of why this solution is effective, refer to the comprehensive explanation provided in this article

Answer №2

To include a Box component within your Grid, simply add the following code snippet:

<Box height="100vh"></Box>

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

Exploring the art of customizing React components with Material UI: Diving into the world

I'm currently diving into Material UI while working on a project in React. I find myself a bit perplexed about the most effective approach to styling and customizing components. Here are some options I've come across: A: Utilizing a custom them ...

"What might be causing the error 'cannot access property 'top' of undefined' while trying to read

My website has a sticky navbar fixed at the top, and this is the structure of my sticky navbar: $(function() { $(window).scroll(function() { if ($(window).scrollTop() > $(".b").offset().top + $(".b").height() && $("input").val() == "") { ...

Utilize identical animations across various elements

I have a canvas animation in JavaScript that is currently limited to one canvas element with the id "stars". I want to be able to use this animation multiple times without repeating the code. Is there a way to add a class for the canvas elements instead of ...

I found myself pondering over possible solutions to rectify this parse error

I need help resolving an issue with parsing. Here is the link to the error image: https://i.stack.imgur.com/jKQat.jpg. Additionally, my HTML code connecting to the CSS site can be found here: https://i.stack.imgur.com/ST31r.jpg. The website I linked in t ...

The inability to access data from an API is a result of the lack of a functioning

I'm encountering an issue with fetching data from an API. When I try to map through my array of data, I receive an error message stating that 'map is not a function'. I fetched the data on the index page and passed it as props to the CoinLis ...

Creating a Modal using Typescript with NextJS

Currently, I'm working on creating a modal within my app using NextJS with Typescript. Unfortunately, I've been struggling to eliminate the warning associated with my modal selector. Can someone provide guidance on how to properly type this? cons ...

What steps can be taken to resolve the vulnerability in webpack-pwa-manifest?

Looking for solutions to address the [email protected] and minimist vulnerability. I attempted removing node/modules and package-lock.json, followed by a fresh npm installation, but the issue persists. Any suggestions would be greatly appreciated. Scr ...

Incomplete Rotation CSS Animation

I am attempting to create a horizontal spinning image using only CSS3. Check out my webpage here: You can find the CSS file here: www.csupomona.edu/~lannguyen/ISSM_WEB/css/main.css The code for calling the spin effect is at the top, with the actual imp ...

How is it possible that my application state is being updated without any change event being triggered by the store

TL;DR Check out this video where I attempt to explain the issue: https://www.youtube.com/watch?v=lJogEfYYHRo&feature=youtu.be I'm currently developing a chat feature for a web application using flux architecture. I have a store with an arra ...

Incorporating the Crypto-js library into an Express application

I’ve encountered an issue while working on a user registration and login system where I am unable to encrypt the data successfully. Below is the Express code snippet: var express = require("express"); var router = express.Router(); var mysql = require ...

Is it possible for a media query to target only 2 elements instead of all 3?

Currently, I am dealing with an older website for a client, and it appears that a media query is not correctly affecting three specific classes out of the total. These problematic classes are .free-ship, .wholesale, .chronicles The CSS styling for these c ...

Dynamic Mat-select-trigger that automatically adjusts its size to fit the content

Currently, I am experimenting with an Angular Mat-Select that allows multiple selections. To display the selected values in the value field, I have implemented a custom Mat-Select-Trigger. My goal is to enable automatic resizing of the value field (similar ...

Unresolved styles in React component linked to styles.css file

As I dive into creating a registration page in ReactJS, I encounter a frustrating issue with my styles not applying correctly from the styles.css file. Let's take a look at my RegisterPage.jsx component: export default function RegisterPage() { ret ...

Z-index problem occurring with rotateY on Safari and Chrome Mobile

https://jsfiddle.net/nxbg7rq3/ I've been struggling to get the .mask completely on top of the .screen in this example. It works fine in most browsers, but Safari and Chrome Mobile are giving me a hard time. I've experimented with various solutio ...

Achieve the effect of bringing the div and its contents to the top when hovered over, all while keeping

I have designed a popup that includes multiple boxes. I want the width of the box to expand and be visible over all content on the webpage when a user hovers over any ".deviceboxes". I tried using ".deviceboxes:hover" which worked fine for the first box in ...

What is the method for retrieving the name of the 'Autocomplete' component in Material UI?

Currently, I am faced with the challenge of working on multiple Autocomplete MUI components and am in the process of creating a "generic" event handler that will utilize the useReducer hook to manage the state. The issue lies in the fact that the onChange ...

Recording audio with Next JS is a breeze

I'm currently working on incorporating audio recording into my Next JS app and could use some guidance. I found a helpful resource at: https://blog.logrocket.com/how-to-create-video-audio-recorder-react/ At this stage, I have the following code snipp ...

What advantage does React gain by utilizing the previous state to update state instead of the current state?

I'm seeking to grasp why it's better to utilize the previous state rather than the current state to update an element in React. Despite seeing this approach commonly used in code examples and tutorials, I haven't come across a satisfactory e ...

Styling with Radial Gradients in CSS

Struggling to create a banner with a radial gradient background? I'm almost there, but my code isn't matching the design. Any assistance would be greatly appreciated as I can't seem to get the right colors and only part of the first circle i ...

Error when using ReactDOM.render with React version 16.5.2: Node not found on component that has been unmounted

After updating my ReactJS project to the latest version using npm update in Visual Studio 2017, I encountered the following results: + @material-ui/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="234a404c4d5063110d130d10">[e ...