CSS"玻璃阴影"效果

Ash*_*n M 5 html css

我正在尝试实现这种阴影效果,其中阴影就像图像本身的模糊版本:

在此输入图像描述

我能够通过将相同的图像堆叠两次并应用于下面的图像来实现它filter: blur(20px),但这感觉就像一种低效的方式:

.cover-wrapper {
  position: relative;
  margin: 50px;
  width: 200px;
  height: 200px;
}

.cover {
  z-index: 1;
  border-radius: 10px;
  position: absolute;
  width: 200px;
  height: 200px;
}

.cover-shadow-wrapper {
  position: absolute;
  filter: blur(20px);
  overflow: hidden;
  height: 200px;
  width: 200px;
}

.cover-shadow {
  transform: scale(1.5)
}
Run Code Online (Sandbox Code Playgroud)
<div class="cover-wrapper">
  <img src="https://picsum.photos/200/200?image=871" alt="cover" class="cover">  
  <div class="cover-shadow-wrapper">
    <img src="https://picsum.photos/200/200?image=871" alt="shadow" class="cover-shadow">
  </div>    
</div>
Run Code Online (Sandbox Code Playgroud)

有更有效的方法吗?此外,这个效果实际上叫什么?

Kri*_*rim 7

它必须是图像标签吗?

你可以使用一个div和它的::在pesudo之后,给它们两个相同的背景图像和属性,然后模糊:: after,你在html中有一个更简单的元素

.glassy-img, .glassy-img::after {
  background-image: url(https://picsum.photos/200/200?image=871);
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  width: 200px;
  height: 200px;
}
.glassy-img::after {
  content: '';
  filter: blur(20px);
  display: block;
  position: relative;
  z-index: -1;
}
Run Code Online (Sandbox Code Playgroud)
<div class="glassy-img"></div>
Run Code Online (Sandbox Code Playgroud)