[英]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:在线试一下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.