Skip to content

Instantly share code, notes, and snippets.

@msreekm
Last active June 10, 2021 08:21
Show Gist options
  • Save msreekm/8a981704b12999017c4596098199476d to your computer and use it in GitHub Desktop.
Save msreekm/8a981704b12999017c4596098199476d to your computer and use it in GitHub Desktop.
Material UI Card component with image overlapped in card header
import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import Card from "@material-ui/core/Card";
import CardActionArea from "@material-ui/core/CardActionArea";
import CardActions from "@material-ui/core/CardActions";
import CardContent from "@material-ui/core/CardContent";
import CardMedia from "@material-ui/core/CardMedia";
import Button from "@material-ui/core/Button";
import Typography from "@material-ui/core/Typography";
const styles = {
card: {
margin: "120px auto 50px",
maxWidth: 345,
overflow: "visible"
},
media: {
margin: "-70px auto 0",
width: "80%",
height: 140,
borderRadius: "4px",
boxShadow: "0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23)",
position: "relative",
zIndex: 1000
}
};
function MediaCard(props) {
const { classes } = props;
return (
<Card className={classes.card}>
<CardActionArea>
<CardMedia
className={classes.media}
image="https://material-ui.com/static/images/cards/contemplative-reptile.jpg"
title="Contemplative Reptile"
/>
<CardContent>
<Typography gutterBottom variant="headline" component="h2">
Lizard
</Typography>
<Typography component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000
species, ranging across all continents except Antarctica
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
<Button size="small" color="primary">
Learn More
</Button>
</CardActions>
</Card>
);
}
MediaCard.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(MediaCard);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment