I am currently using the Material UI Card
and CardMedia
components in my application, but I am having trouble with overlaying text on top of the image. Below is a simplified version of what I have been attempting:
<Card>
<CardMedia image={this.props.preview} style={styles.media}/>
<div style={styles.overlay}>
this text should overlay the image
</div>
</Card>
const styles = {
media: {
height: 0,
paddingTop: '56.25%' // 16:9
},
overlay: {
position: 'relative',
top: '20px',
left: '20px',
color: 'black',
backgroundColor: 'white'
}
}
I have attempted various placements for the text div such as above the CardMedia
, below it, inside it, outside the Card entirely, and experimenting with different position values without success. The beta versions of MUI had an overlay property on the CardMedia
, but the v1 library does not seem to have that feature.
If anyone has expertise in properly achieving this effect, I would greatly appreciate any guidance. Thank you in advance for your assistance!