简体   繁体   English

如何使用 Material UI Card 和 CardMedia 在背景图像上添加一些文本

[英]How can I add some text on a background image with Material UI Card and CardMedia

So I've used the card component to create my background image however, I'm not sure how to add text on the image.所以我使用卡片组件来创建我的背景图像,但是,我不确定如何在图像上添加文本。 There might be a better way as well, I'm open to other ideas.也可能有更好的方法,我对其他想法持开放态度。

<Card>
    <CardMedia
        component="img"
        alt={header.bg_img}
        src={process.env.API_URL + header.bg_img.url}
        title="Background Image"
      />
      <CardContent>
           <h2 className={classes.h2}>{header.title}</h2>
           <p className={classes.paragraph}>{header.small_description}</p>
      </CardContent>
</Card>
<Card className={classes.root}>
  <CardMedia
    component="img"
    alt="Contemplative Reptile"
    height="200"
    image={Header}
    title="Contemplative Reptile"
  />
  <Typography
    gutterBottom
    variant="h1"
    component="h1"
    className={classes.font}
  >
    Weather
  </Typography>
</Card>
const useStyles = makeStyles(theme => ({
  root: {
    position: "relative"
  },
  font: {
    position: "absolute",
    top: "20%",
    width: "100%",
    textAlign: "center",
    color: "black",
    backgroundColor: "none",
    fontFamily: "Comic Sans MS"
  }
}));

在此处输入图片说明

Try it online:在线试一下:

编辑深情euler-0rwi7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM