The implementation of display flex is causing issues with the material-ui grid layout

Struggling to implement the grid system from material-ui due to an issue where grid items do not resize when resizing the browser window. The culprit seems to be a parent div with the style property "display": "flex".

The dilemma arises from using a material-ui app-bar and drawer, as well as creating a reusable container component for all content and children. Removing the style property "display": "flex" leads to a broken page style. How can this conundrum be solved?

Below is my code snippet showcasing the class root with the property "display": "flex".

Container.tsx

return (
        <div className={classes.root}>
            <TopBar /> // Material-UI AppBar
            <Drawer /> // Reusable Drawer Component
            <main className={classes.contentContainer}>
                <div>{children}</div>
            </main>
        </div>
    );

Container Styles

const useStyles = makeStyles((theme: Theme) =>
createStyles({
    contentContainer: {
        flexGrow: 1,
        marginTop: 63,
        position: 'relative',
        backgroundColor: colors.whiteB_8,
        height: `calc(100vh - 63px)`,
        '& > div:first-child': {
            padding: `calc(${theme.spacing(1)}px + 35px)`,
        },
    },
    root: {
        display: 'flex',
    },
}),

);

To illustrate, here is an example component containing three columns inside the content container:

return (
    <Grid container item xs={12} spacing={2}>
        <Grid item xs={4}>
            <Paper
                style={{ backgroundColor: 'grey' }}
            >
                Test
            </Paper>
        </Grid>
        <Grid item xs={4}>
            <Paper
                style={{ backgroundColor: 'grey' }}
            >
                Test
            </Paper>
        </Grid>
        <Grid item xs={4}>
            <Paper
                style={{ backgroundColor: 'grey' }}
            >
                Test
            </Paper>
        </Grid>
    </Grid>
);

The displayed output does not show resized items despite efforts to rectify the issue.

If the "display": "flex" style is removed, the consequence is shown in the image below with the content positioned beneath the drawer link:

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

Answer №1

While I can't replicate your exact issue, it seems like adding width: '100%' along with display: 'flex' could potentially solve the problem you are experiencing. Currently, without a specified width for the flexbox, it will only resize to accommodate its contents but won't shrink any further when the window size decreases. By setting a relative width using either % or vw, the content should respond better to resizing.

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

The alignment of links is not meeting the centering requirement

I'm facing a challenge with aligning my "buttons" on the pages, although they are essentially text links designed to resemble buttons using CSS. These buttons are utilized within an unordered list structure (refer to the HTML snippet below). The rele ...

Having trouble eliminating the underline on Vue router-link?

I've experimented with various approaches in an attempt to remove the underline from router-link. This is the code I have: <router-link :to="{name: 'Plan'}"> <div>Plan Your Trip</div> <div class=&apos ...

Adding property to an object retrieved from an API in a React application can be achieved effortlessly by utilizing the useState

How can I implement a toggle functionality for Bookmarked Meals on my Meal Recipe Website available at ? I am currently using the logic to set data.meals[0].bookmarked to true or false, but I want to use setState instead in order to rerender the page when ...

I assigned a key prop to the child component, but I am still encountering the error message: "Each item in a list must have a distinct 'key' prop"

I am currently utilizing MongoDB and Express for the backend of my project. Here is part of my component: return ( <> <Addnote /> <div className="row my-3"> {notes.map((note) => { ...

Retrieving posts by their ID leads to consistently fetching the most recent post in WordPress

My goal is to fetch a specific post based on its ID. Within my custom post type Stories, there are currently three posts available: Blog 1 (ID: 1) Blog 2 (ID: 14) Blog 3 (ID: 49) I have defined a variable called $story_one with the value of 14. Now, my ...

Buttons for concealment and revelation are unresponsive

I have the following code snippet for uploading an image, which is taken from a template utilizing bootstrap 2. <div class="span6"> <div class="control-group"> <label class="control-label">Imagen</label> <div cla ...

position an element at a higher level than the #top-layer

I developed a custom tool and utilized z-index to position it above all other elements: .customTool { position: fixed; z-index: 99999; } However, this functionality stops working when a modal <dialog /> element is opened in modal mode. As a res ...

What is the best way to present a unique page overlay specifically for iPhone users?

When browsing WebMD on a computer, you'll see one page. However, if you access it from an iPhone, not only will you be directed to their mobile page (which is easy enough), but they also display a special overlay with a "click to close" button prompti ...

Combing external JavaScript with React functionality

Hey there, I've been working on merging two projects that I came across recently: https://github.com/danxfisher/MeetEasier and this awesome page https://tympanus.net/Development/Interactive3DMallMap/ After making some changes in the MeetEasier React ...

Canvas - Drawing restricted to new tiles when hovered over, not the entire canvas

Imagine having a canvas divided into a 15x10 32-pixel checkerboard grid. This setup looks like: var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); var tileSize = 32; var xCoord var yCoord ...

Prevent unnecessary list re-rendering in React by updating only the newly added images

My react component is experiencing a re-rendering issue every time a new image is added to the item list. Below is the useEffect code used to load image URLs from the database: const [imageUrls, setImageUrls] = useState({}); // Effect to fetch image UR ...

React-vertical-timeline component is failing to display on the webpage. The content in the output HTML remains concealed due to the presence of the "is-hidden"

I am facing an issue while trying to incorporate a vertical timeline into my project. The generated HTML code does not display the timeline as expected. Upon inspection, I noticed that the classes are set to be hidden with "is-hidden". It seems like there ...

Issue with setting cookies using res.cookie

Currently, I am in the process of setting up a Node/Express application with a React client for interaction. I have configured passport to manage authentication using JWT. Upon user login, I verify the email and password, then set the cookie: res.cookie(& ...

Recalling the layout following the user's computer restart

I am creating a simple online editing tool (similar to Microsoft Outline) for coursework and I would like the outline details to be saved even if the user restarts the system. How can I achieve this? <html> <head> <title>Editor</ ...

Deleting a property once the page has finished loading

My issue is a bit tricky to describe, but essentially I have noticed a CSS attribute being added to my div tag that seems to come from a node module. The problem is, I can't seem to find where this attribute is coming from in my files. This attribute ...

Is there a way to customize the appearance of an unordered list by setting it to display as an image instead of default bullets? I want to

I have been attempting to achieve this desired outcome. However, my efforts to reproduce it resulted in the check marks being rendered at a smaller size than intended due to using an SVG file. An example of this issue can be seen in the following image: I ...

Is there a way to track the number of visits by a 'user' to a website?

Looking to hide certain parts of my website from users who have visited more than a specified number of times. The NY Times site has something similar. Utilizing react & firebase for this project. Considered using IP addresses, but it seems to identify l ...

When the React application loads, loadingbar.js will be mounted initially. However, as the props or states are updated, the object

I recently made the switch from using progressbar.js to loadingBar.js in my React application for widget progress. Everything was working smoothly with progressbar.js, but once I switched to loadingBar.js, I encountered a strange issue. After the page load ...

Trouble with CSS in a WordPress theme utilizing a two-column layout

After setting up my wordpress blog (http://raptor.hk), I encountered an issue with aligning the right sidebar correctly. It seems like I have overlooked something in the CSS code. The div responsible for the sidebar has been assigned the name "rightbar". I ...

Prevent parent element from changing color when child element is clicked

Check out my HTML: .imageURL:active .image_submit_div { background-color: #ccc; } .image_submit_div:active { background-color: #e6e6e6; } <div class="image_div"> <label for="id_image" class="image_submit_div"> <h3>+ add ...