Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

css - How to center grid elements in a container MUI?

The following is the code snippet which I am trying to implement.

<Container className={Styles.projectSelection}>
            <Grid container item spacing={8} alignItems="center">
                <Grid item>
                    <Typography variant="h3" color="primary">
                        Projects
                    </Typography>
                </Grid>
                <Grid item>
                    <Searchbar />
                </Grid>
            </Grid>
            <Grid container item></Grid>
            <Grid container item>
                <Grid item>
                    <Button startIcon={<AddRounded />}>Create Project</Button>
                </Grid>
            </Grid>
        </Container>

for projectSelection class

.projectSelection {
    display: flex !important;
    flex-direction: column;
    align-items: center;
}

If there is another component inside container such as h1 tag, properties as defined under projectSelection class are working but why they are failing with grid?

question from:https://stackoverflow.com/questions/65545604/how-to-center-grid-elements-in-a-container-mui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<Grid container item spacing={8} justify="center">
    <Grid item></Grid>
    <Grid item></Grid>
</Grid>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...