user460567
user460567

Reputation: 133

How can I centre these 2 graphs in their respective grids in Material UI?

I have 2 graphs side by side. But they are not at the centre and this looks a bit awkward. The code:

   <Box  sx={{ flexGrow: 1 }} display="flex"
  justifyContent="center"
  alignItems="center" marginLeft={3} marginRight={3} mt={2.5}>
      <Grid container spacing={{ xs: 1, md: 2,lg:2}} columns={{ xs: 2, sm: 2, md: 12 ,lg:16}} display="flex"
  justifyContent="center"
  alignItems="center" >
  
          <Grid item xs={2} sm={4} md={4} lg={7.3} >
            <Item alignItems="center"><Nifty50/></Item>
          </Grid>

          <Grid item xs={2} sm={4} md={4} lg={7.3}>
            <Item alignItems="center"><Sensex/></Item>
          </Grid>
      
      </Grid>

    </Box>

enter image description here

I would like to position the graphs in the centre so the grey background is evenly distributed. Any help is appreciated.

Upvotes: 0

Views: 39

Answers (1)

Filali Mohamed Amar
Filali Mohamed Amar

Reputation: 1

You have to put all the css into the sx attribute

  <Box  sx={{ flexGrow: 1, display: "flex", justifyContent: "center", alignItems: "center", marginLeft: 3, marginRight: 3, marginTop: 2.5 }}>
      <Grid container spacing={{ xs: 1, md: 2,lg:2}} columns={{ xs: 2, sm: 2, md: 12 ,lg:16}} sx={{ display: "flex", justifyContent: "center", alignItems: "center" }}>
  
          <Grid item xs={2} sm={4} md={4} lg={7.3} >
            <Item alignItems="center"><Nifty50/></Item>
          </Grid>

          <Grid item xs={2} sm={4} md={4} lg={7.3}>
            <Item alignItems="center"><Sensex/></Item>
          </Grid>
      
      </Grid>

    </Box>

Upvotes: 0

Related Questions