reactjs - CardMedia images not fitting inside tag - Stack Overflow

I am building a demo of a website selling games. My images due to their heights and widths aren't

I am building a demo of a website selling games. My images due to their heights and widths aren't fitting uniformly to CardMedia.

So in the first row they don't have any padding top and in the second row all but one do. Also they have different sizes.

I tried using objectFit but it didn't help.

My markup:

  return (
    <>
      <Card
        elevation={3}
        sx={{
          width: 280,
          borderRadius: 3,
          display: 'flex',
          flexDirection: 'column',
          justifyContent: 'space-evenly',
        }}
      >
        <CardMedia
          component='img'
          sx={{height: 280, backgroundSize: 'cover' , objectFit: 'contain', width: '100%'}}
          image={game.pictureUrl}
          title={game.name}
        />
        <CardContent>
           {/* other markup */}
        </CardContent>

        <CardActions>
          <Button>Details</Button>
        </CardActions>
      </Card>
    </>
  );

I am building a demo of a website selling games. My images due to their heights and widths aren't fitting uniformly to CardMedia.

So in the first row they don't have any padding top and in the second row all but one do. Also they have different sizes.

I tried using objectFit but it didn't help.

My markup:

  return (
    <>
      <Card
        elevation={3}
        sx={{
          width: 280,
          borderRadius: 3,
          display: 'flex',
          flexDirection: 'column',
          justifyContent: 'space-evenly',
        }}
      >
        <CardMedia
          component='img'
          sx={{height: 280, backgroundSize: 'cover' , objectFit: 'contain', width: '100%'}}
          image={game.pictureUrl}
          title={game.name}
        />
        <CardContent>
           {/* other markup */}
        </CardContent>

        <CardActions>
          <Button>Details</Button>
        </CardActions>
      </Card>
    </>
  );

Share Improve this question asked Mar 31 at 17:18 X HOxhaX HOxha 1771 gold badge3 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

change from

objectFit: 'contain'

to

objectFit: 'cover',

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743931842a4531952.html

相关推荐

  • reactjs - CardMedia images not fitting inside tag - Stack Overflow

    I am building a demo of a website selling games. My images due to their heights and widths aren't

    2天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信