最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Material Ui Avatar add elevation - Stack Overflow

programmeradmin3浏览0评论

I try to add elevation(shadow) to a MUI Avatar ponent .

<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 / but without success.

I try to add elevation(shadow) to a MUI Avatar ponent https://material-ui./ponents/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./system/shadows/ but without success.

Share Improve this question asked Jun 16, 2020 at 16:49 ohlrohlr 1,9092 gold badges16 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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],
    }
}))

Found an alternative solution myself:

<Avatar ponent={Paper} elevation={2}>
    <DirectionsCarIcon />
</Avatar>
发布评论

评论列表(0)

  1. 暂无评论