I have a row of cards inside a container that I want to align in the center with equal spacing around them.
I am using the material-ui UI library for the layout. Despite adding the justifyContent: center
property, the cards are not evenly spaced.
This is how the current UI appears:
https://i.sstatic.net/fo2iz.png
There seems to be extra space on the right side of the last card. The spacing scale reveals this:
Here's the code snippet so far:
const Home = ({ cards }) => {
return (
<Container maxWidth="xl">
<Grid
container
justifyContent="center"
spacing={3}
my={8}
>
{cards.map((card) => {
return (
<Grid item xs={12} sm={6} md={3}>
<Card sx={{ maxWidth: 300 }}>
<CardActionArea>
<CardMedia
component="img"
height="140"
image="../../bg2.png"
alt="green iguana"
/>
<CardContent>
<Typography gutterBottom variant="h5" component="div">
{card.title}
</Typography>
<Typography variant="body2" color="text.secondary">
{card.description}
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary">
View More
</Button>
</CardActions>
</Card>
</Grid>
);
})}
</Grid>
</Container>
);
};
If I remove the container wrapper
<Container maxWidth="xl">
, then the UI looks like this:
https://i.sstatic.net/xmnnG.png
I'm not very experienced with MUI, so any help in fixing this issue and achieving the desired layout would be greatly appreciated.