My goal is to achieve something similar to sunset highlighted.
This example image uses 4 semi-transparent black squares, on the right, left, top and bottom to simulate the effect I'm after

使用看起来有点像这样的代码:

.wrapper {
  position: relative;
  width: 400px;
  height: 200px;
}

.overlay {
  position: absolute;
  background-color: #0005;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}

.transparent-box {
  background-color: #fff0;
  position: absolute;
  top: 50px;
  left: 50px;
  width: 100px;
  height: 80px;
}
<!DOCTYPE html>
<html>
    <body>
      <div class="wrapper">
        <img src="https://picsum.photos/400/200" alt="">
        <div class="overlay">
          <div class="transparent-box"></div>
        </div>
      </div>
    </body>
</html>

I would like to be able to get this effect with while using oneelement for the background and one element making the "window" so that for example adding rounded courners and similar styling could be done easier.
I've tried playing around with blend modes, but I'm not sure if it doesn't support that or if I've just set it up wrong.

推荐答案

要获得同样的效果,一个很好的技巧是在叠加上使用一个长方体阴影:

.overlay {
    box-shadow: 0px 0px 1px 100vmax rgba(0,0,0,0.5);
}

在这种情况下,100vmax会填满整个页面.

Html相关问答推荐

将文本区域标签的内容着色为SON(带有 colored颜色 )

使用Scrapy Select 最后一个子文本

如何将FlexBox项目zoom 到其包含图像的大小

在浮动元素旁边垂直居中

使用无限数量的元素创建特定的CSS网格

如何在伪元素背景中定位多个CSS径向梯度

如何在元素的三条边中间换行边框?

仅在加载视频时显示描述(<;Video>;标签)

如何创建嵌套的动态表单元素

根据Tailwind CSS中的子计数而非子宽度进行对齐,并水平对齐

仅 Select 悬停的级别,而不 Select 其父级或子级

如何在 Bootstrap 5 中将两个导航栏元素放在末尾?

带标签 css 的 div 内的中心图标

CSS 随着内容宽度的增加而减少填充