Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use MUI's shadows?

Tags:

I would like to add a shadow to a <Grid container> component.

I see in the documentation here. I should just use something like boxShadow={1} and import import { shadows } from '@material-ui/system';.

I've done this, but am not getting any results.

Would anyone know the correct way to add shadows to a component?

like image 203
MeltingDog Avatar asked May 11 '20 04:05

MeltingDog


People also ask

How does box shadow work?

The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.


1 Answers

Since <Grid /> doesn't have the props boxShadow,

Use <Box /> with its component as Grid would be fine.

<Box
  component={Grid}
  container
  boxShadow={3}
>
  <Box ... />
  <Box ... />
  ...
</Box>

Refer:

  • MUI Box props API

  • MUI Grid props API


Demo and source:

<Box
  component={Grid}
  container
  boxShadow={3}
  spacing={3}
  style={{ padding: 10 }}
>
  <Box component={Grid} item boxShadow={0} xs={3}>
    boxShadow={0}
  </Box>
  <Box component={Grid} item boxShadow={1} xs={3}>
    boxShadow={1}
  </Box>
  <Box component={Grid} item boxShadow={2} xs={3}>
    boxShadow={2}
  </Box>
  <Box component={Grid} item boxShadow={3} xs={3}>
    boxShadow={3}
  </Box>
</Box>

enter image description here

like image 92
keikai Avatar answered Sep 30 '22 19:09

keikai