Align a component vertically in a FlexBox using Material UI

I have a React app where I created a card with specified min width and height, containing only a header. I want to add flexbox that occupies the entire left space with justify-content="center" and align-items="center". This way, when I insert a circular progress element, it will be at the center of the card. However, no matter what I try, the flexbox's height matches the loading spinner's height and doesn't take up the full space. How can I resolve this issue? My Component:

   function AccountSettings({isLoading, id, username, isDisable}) {
        const classes = useStyles();

        return (
            <Card
                className={classes.accountSettings}
            >
                <CardHeader
                    title="Something"
                />
                <Divider/>
                    <Box
                        display="flex"
                        alignItems="center"
                        justifyContent="center"
                        height={"100%"}
                        width={"100%"}
                    >
                        <CircularProgress/>
                    </Box>
            </Card>
        );
    }

My style:

import {makeStyles} from "@material-ui/styles";

export default makeStyles(theme => ({
    root: {
        maxWidth: "1000px"
    },
    pageTitle: {
        padding: "5px"
    },
    accountSettings: {
        minWidth: "312px",
        minHeight: "273px",
    }
}));

Here is my main view:

<div className={classes.root}>
    <AccountSettings/>
</div>

This image illustrates my problem: https://i.stack.imgur.com/9bNRr.png

Answer №1

Check out this solution

Include the following styles:

accountSettings: {
  display: 'flex',
  flexDirection: 'column'
},
box: {
  flexGrow: 1
}

Then, assign the class to the Box element:

<Box
  className={classes.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

Generate a new div element dynamicaly after every 10 elements are added

I am facing the following scenario: I need to dynamically add an UNKNOWN number of checkboxes to a layout component, arranged in columns with 10 checkboxes per layout item. Although I have successfully added all the checkboxes to a single div element, I ...

Is it time to say goodbye to MUI Material UI React Hook useTheme(), and if so, what should we replace

Is there a way to access theme props outside of JSX and CSS without using the legacy React Hook useTheme() or the sx prop? Imagine I have a component with complex logic that requires custom theme properties in certain handlers, but I want to avoid relying ...

When attempting to dynamically assign route parameters in React-Router V4 using code, the result leads to the error message "Page not found."

I am attempting to dynamically set a route parameter from a function in a component. Here is the code snippet: this.props.history.push({ pathname: '/SupportSectionReports', search: '?reportType=0' }); This is how I have co ...

Using HTML and CSS to create nested divs floating to the left while also incorporating a

I'm trying to create a simple effect where a fixed height and width div contains a series of child divs that can be scrolled horizontally. However, the children are not floating as expected in the following code: .a {width:200px; height:200px; ...

Using the appropriate asynchronous action in Redux with the Redux-Thunk middleware

While learning middleware redux-thunk, I created a simple React App. However, I am facing a transpilation issue due to an incorrect type of async action fetchPosts in the interface PostListProps. Below is the code snippet of the functional component where ...

Measuring the quantity of 'table' elements with jQuery

This HTML code below defines a table structure. Now tables can be dynamically added to this structure. <div class="tableStyle myWebsiteTable"> <table cellspacing="0" cellpadding="0" id="site0" class="site active"> <thead> ...

Error: The name property is not defined and cannot be read in the Constructor.render function

Having trouble building a contact form and encountering an error when trying to access the values. I've checked for bugs in the console multiple times, but it seems like something is missing. Can anyone provide assistance? var fieldValues = { ...

Can JavaScript trigger an alert based on a CSS value?

Hello, I am facing an issue. I have created a blue box using HTML/CSS and now I want to use JavaScript to display an alert with the name of the color when the box is clicked. Below is my code: var clr = document.getElementById("box").style.background ...

React Material-UI - implementing custom colors in Alert component leads to error: "Cannot read properties of undefined (reading 'type')"

I've been working on customizing MUI components to match our company's design, but I've hit a roadblock. While defining my custom colors, I noticed that instead of "error" we have a color called "danger." I followed the guidelines in the do ...

Upon opening index.html in the browser, the jQuery code fails to execute, as no errors are displayed in the console

I am struggling to make a simple toggleClass() function work in jQuery and I can't seem to figure out why. This is just a beginner exercise for me with jQuery. The code works perfectly when I test it as a snippet or manually in the console, but when I ...

Employing "npm install" to set up the development environment within Docker

Currently, I am working on a ReactJS project using Docker for development purposes and will be collaborated on by a team. I am encountering some difficulties understanding the process because I want to share my 'app' directory as a volume into t ...

What is the best way to clear a TextField in Java?

Is there a way to make the text field display empty if the column is null? Currently, when using an empty string as the value, the label appears in the position of the actual value. How can this be improved? <TextField margin="normal" ...

Encountering a 500 internal server error after deploying due to utilizing getServerSideProps in Next.js

When trying to redeploy my website on Vercel, I added getServerSideProps to my index.js file. However, I encountered an error that I am not familiar with. The program works perfectly on localhost. This is the getServerSideProps code that I added: export a ...

Challenges associated with Bootstrap toggle switch

I am having some difficulties with using bootstrap switch. I have tried the examples provided on , but regardless of the classes I apply, the buttons remain the same small size and the text for ON and OFF is barely visible. I can't seem to figure out ...

Customize Angular Material styles uniquely across various components

Within my application, I am utilizing two components that contain tab groups. The first component serves as the main page, where I have adjusted the CSS to enlarge the labels by using ViewEncapsulation.None. The second component is a dialog, and I aim to m ...

Is the new mui LoadingButton not available in the latest version?

According to the material UI documentation found at here, you are supposed to import LoadingButton from '@material-ui/lab/LoadingButton'; However, I am unable to locate this folder within mui/lab and the import statement is resulting in an erro ...

uncertainty surrounding the concept of Cross-Site Request Forgery (CSRF) Vulnerabilities

Trying to understand the concept of CSRF attack and how adding a CSRF token helps prevent it. For instance, imagine a bank website that includes a CSRF token in all transaction forms. If a user is logged into an active session and visits a phishing website ...

Tips for changing the background color of a dropdown menu when hovering in Zurb Foundation 5

Is there a way to customize the background color when hovering over <a href="#">Find Me</a>? I want the background color to change while hovering, similar to how it appears in the image before hovering. And this is how it looks after hovering: ...

More content will not be displayed beneath folded DIVs arranged to stack on mobile devices

On my website, I have two separate sections dedicated to use cases and benefits. Here is the code: .onboardmessaging { min-width: 100%; } .onboardmessagingwrap { min-width: 100%; } .usecase { padding-left: 8vw; max-widt ...

When MUI Radio is selected, it passes both the label and value in the onChange event

I am currently working with reactjs and I have a MUI RadioGroup component. My goal is to pass the selected value's label along with it. Here is my Radio Button Code <RadioGroup aria-label="am-time-in" value={state.AM_time_in_valu ...