CSS 变换和悬停时的框阴影

Kat*_*ate 2 css transform material-ui card

我有使用 Material UI 的卡片组件。该卡在悬停时会发生变化,并且卡上也应该出现阴影。但是当我把盒子阴影放在转换之前的盒子上时,阴影就会出现,并且转换后的卡片和阴影之间有空白。我怎样才能解决这个问题?

const CardStyle = styled(Card)`
  background: red;
  transition: transform 50ms;
  &:hover {
    transform: scale(1.02) perspective(0px);
    box-shadow: ${({ theme }) => theme.shadows[4]};
  }
`;
Run Code Online (Sandbox Code Playgroud)

其他方式相同的输出:

:hover {
  transform: scale(1.02) perspective(0px);
  box-shadow: 4px 4px 4px rgba(60, 60, 93, 0.33)
}
Run Code Online (Sandbox Code Playgroud)

Chr*_* W. 5

box-shadow如果我正确理解您的意图,请为您提供过渡。

div {
  height: 5rem;
  width: 5rem;
  margin: 3rem auto;
  border: green 5px dashed;
  background: red;
  transition: transform .5s, box-shadow 1s;
}

div:hover {
  transform: scale(1.02) perspective(0px);
  box-shadow: 0 10px 10px rgba(255,0,0,.7);
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)