CSS - 对角线模糊 overlays/background 的图像

CSS - image with overlays/background blurred diagonal

我希望 "whited" 的部分使图像模糊。

我试过使用伪元素 ::after 和 ::before 来添加叠加层,但只能模糊叠加层。

尝试使用 borders 2nd example codepen,但没有成功,因为透明的它创建了 "square".

https://codepen.io/giventofly/pen/RQpqYZ

.hero-image {
  width: 1280px;
  height: 800px;
  background-image: linear-gradient(rgba(46, 51, 82, 0.6) 100%, transparent 0), linear-gradient(125deg, rgba(255, 255, 255, 0.5) 35%, transparent 0), linear-gradient(-55deg, rgba(255, 255, 255, 0.5) 25%, transparent 0),
                    url('https://cdn.vox-cdn.com/thumbor/NU6lcSN3DGmjF7NhZp6ixY3HxgQ=/0x0:1620x1080/1200x800/filters:focal(0x0:1620x1080)/cdn.vox-cdn.com/uploads/chorus_image/image/46510678/Tarmogoyf_DGM_1920x1080_Wallpaper.0.0.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;   
  z-index: 10;
}

<div class="hero-image"></div>

我只想模糊图像的一部分,即 "behind" 白色线性渐变

您可以为此使用 clip-path。这个想法是有两个相似的图层,顶部带有剪辑路径以仅显示需要的部分并保持底部图层的模糊可见。如果你想模糊中间部分,你可以在两个元素之间切换模糊:

.hero-image {
  width: 600px;
  height: 250px;
  position: relative;
  overflow: hidden;
}

.hero-image:after,
.hero-image:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background: center/cover no-repeat;
  background-image: 
   linear-gradient(rgba(46, 51, 82, 0.6) 100%, transparent 0), 
   linear-gradient(125deg, rgba(255, 255, 255, 0.5) 35%, transparent 0), 
   linear-gradient(-55deg, rgba(255, 255, 255, 0.5) 25%, transparent 0), 
   url('https://picsum.photos/id/1024/800/800');
}

.hero-image:before {
  filter: blur(4px);
}

.hero-image:after {
  clip-path: polygon(45% 0, 97% 0, 68% 100%, 16% 100%);
}
<div class="hero-image"></div>

我相信有人可以稍微改进这种方法,但主要的收获是:

  • 在容器元素中两次包含图像。
  • 叠放两张图片。
  • 模糊一个放在最下面。
  • 在顶部图像上使用 clip-path 以显示非模糊区域。
  • 在两张图片之间插入一个容器元素伪元素的霜层(透明白)
  • 使用定位和 z-index 控制分层。

.img-overlay {
  display: inline-flex;
  position: relative;
  overflow: hidden;
}

.img-overlay::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba( 255, 255, 255, 0.5 );
  z-index: 1;
}

.img-overlay img:first-child {
  position: absolute;
  top: 0;
  left: 0;
  filter: blur( 3px);
  z-index: 0;
}

.img-overlay img:last-child {
  position: relative;
  z-index: 2;
  -webkit-clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
  clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
}
<div class="img-overlay">
  <img src="http://unsplash.it/400/400?image=16">
  <img src="http://unsplash.it/400/400?image=16">
</div>