Reputation: 321
Please help, its driving me crazy, feels like this should be so simple.
I can't seem to center
an image/avatar in the middle of a Card
component I'm trying to create.
Tried alignText
,alignItems
, alignContent
, justify
.
I even tried which worked but is obviously now obsolete...
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
import Avatar from '@material-ui/core/Avatar';
import Dankirk from '../assets/img/dankirk.jpg'
const useStyles = makeStyles({
card: {
width: "100%",
minHeight: "150px",
borderRadius: "0px",
},
title: {
fontSize: 14,
textAlign: "center"
},
pos: {
marginBottom: 12,
},
avatar: {
margin: 10,
width: 120,
height: 120,
},
});
export default function SimpleCard() {
const classes = useStyles();
return (
<div className={classes.root}>
<div className={classes.container}>
<Card className={classes.card}>
<CardContent style={{justifyContent: 'center'}}>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Test
</Typography>
<Avatar alt="avatarimage" src={name} className={classes.avatar} />
</CardContent>
</Card>
</div>
</div>
);
}
Image just stays to the left...
Upvotes: 3
Views: 13075
Reputation: 1100
You just have to use margin: "auto" like this:
<Avatar alt="Travis Howard" src="/students/gaby.svg" sx={{ height: "64px", width: "64px", margin: "auto" }} />
Upvotes: 2
Reputation: 1
Also try do add lineHeight: 0, letterSpacing: 0 to Avatar component
Upvotes: 0
Reputation: 314
Can you try display flex:
style={{ justifyContent: "center", display: "flex" }}
Upvotes: 16