I’m looking to change a Card with only an image to a Card with content. Essentially on my portfolio, I’d like to display my project’s logo and then while hovering over it, it should show the title/languages used/description. I currently have my code as:
<Card sx={{ width: 1, height: 250 }}>
<CardActionArea>
<CardMedia
sx={{
height: 250,
':hover': {
// call a function here I believe?
},
}}
image={project.image}
title="green iguana"
/>
</CardActionArea>
</Card>
2
Answers
You can only trigger
CSS
usingsx
prop of MUI. To trigger functions you can wrap yourCard
components with adiv
and useonMouseEnter
andonMouseLeave
properties.Here is a very basic example of it:
I hope it helps.
Simran Singh has the right idea. However the sample code changes CSS properties of the CardMedia component, while the question asks how to change the content of the MUI Card itself. The sample below changes the content of the MUI Card. It can be seen in this live demo. The demo code repository is available. The main code for the component is below.
app.jsx
Update
Hover effect for multiple Cards
The needed changes are within the lines of the code shown below.