Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Ui Avatar add elevation

I try to add elevation(shadow) to a MUI Avatar component https://material-ui.com/components/avatars/#image-avatars.

<Avatar alt="Cindy Baker" src="/static/images/avatar/3.jpg" />

Wrapping the Avatar with paper or Card increases the radius.

I also tried setting boxShadow of the Avatar using makeStyles and MUI shadow https://material-ui.com/system/shadows/ but without success.

like image 962
ohlr Avatar asked Feb 01 '26 05:02

ohlr


2 Answers

I have tested, and it works with shadow. Here is my code:

import React from 'react'
import { makeStyles } from '@material-ui/styles'
import Avatar from '@material-ui/core/Avatar'

export default () => {

    const classes = useClasses()

    return (
        <Avatar
            className={classes.avatar}
            alt="Cindy Baker"
            src="/static/images/avatar/3.jpg"
        />
    )
}

const useClasses = makeStyles(theme => ({
    avatar: {
        boxShadow: theme.shadows[3],
    }
}))
like image 193
CevaComic Avatar answered Feb 02 '26 19:02

CevaComic


Found an alternative solution myself:

<Avatar component={Paper} elevation={2}>
    <DirectionsCarIcon />
</Avatar>
like image 36
ohlr Avatar answered Feb 02 '26 19:02

ohlr