How to adjust the size of the MUI-card for small screen?

Viewed 21

The card width looks too small on small screen sizes, how can I adjust its width?

I recreated this in codesandbox: https://codesandbox.io/s/nameless-darkness-d8tsq9?file=/demo.js

The width is too small for this screen size:

enter image description here enter image description here

codes:

export default function ImgMediaCard() {
  return (
    <section style={{ padding: "5rem", flexGrow: "1" }}>
      <Box sx={{ display: "flex", justifyContent: "center", flexWrap: "wrap" }}>
        <Card sx={{ maxWidth: 350, margin: "1rem" }}>
          <CardMedia
            component="img"
            alt="green iguana"
            height="200"
            image="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"
          />
          <CardContent>
            <Typography gutterBottom variant="h5" component="div">
              Lizard
            </Typography>
            <Typography variant="body2" color="text.secondary">
              Lizards are a widespread group of squamate reptiles, with over
              6,000 species, ranging across all continents except Antarctica
            </Typography>
          </CardContent>
          <CardActions>
            <Button size="small">Share</Button>
            <Button size="small">Learn More</Button>
          </CardActions>
        </Card>
        {/* 2nd card */}
        <Card sx={{ maxWidth: 350, margin: "1rem" }}>
          <CardMedia
            component="img"
            alt="green iguana"
            height="200"
            image="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"
          />
          <CardContent>
            <Typography gutterBottom variant="h5" component="div">
              Lizard
            </Typography>
            <Typography variant="body2" color="text.secondary">
              Lizards are a widespread group of squamate reptiles, with over
              6,000 species, ranging across all continents except Antarctica
            </Typography>
          </CardContent>
          <CardActions>
            <Button size="small">Share</Button>
            <Button size="small">Learn More</Button>
          </CardActions>
        </Card>
      </Box>
    </section>
  );
}
1 Answers

I found padding 5rem on the below section that's why you are not getting much space on the small screen. Instead of inline padding you can add a class and define the padding in the CSS file and use media query for small devices that will fix your issue.

<section style={{ padding: "5rem", flexGrow: "1" }}>
Related