需要帮助获得背景以比剪报更复杂的方式通过某些文本显示

Need help getting a background to show through some text in a more complex way than clipping offers

请参阅附件图片了解我正在努力实现的目标。

基本上我需要背景图像穿过文本,除了文本与褪色面板重叠的地方。这需要文本与面板本身相同 colour/opactity。

这让我很头疼,但想看看 far/what 解决方案如何实现我的目标。

谢谢,哈利。


编辑 1:如果您想测试任何内容,这里有一个代码笔 https://codepen.io/itsharryfrancis/pen/XVagep

我试过将它与它一起使用,但确实如此

-webkit-background-clip: text;
-webkit-text-fill-color: transparent;

编辑 2:我将在这里留下一个代码笔,它是我目前拥有的最新版本,供将来可能希望看到它的任何人使用。

https://codepen.io/itsharryfrancis/pen/goxVQP?editors=0100

这是实现所需外观的工作示例,但它在 IE 和 Edge 中使用了相对较新的 clip-path property that is not supported。这个问题可以通过使用 SVG 裁剪代替(或作为回退)来解决,但我希望这足以开始。

.example {
    width: 600px;
}

.example {
    background: url('http://dummy-images.com/nature/dummy-1024x576-Waterfalls.jpg');
    background-position: center center;
    background-size: cover;
    position: relative;
}

.text {
    width: 100%;
    font-family: Helvetica, Arial, sans-serif;
    font-weight: 300;
    font-size: 100px;
    line-height: 1.0;
    text-transform: uppercase;
}

.part1, .part2 {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.part1:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 400px;
    background-color: rgba(255, 255, 255, 0.5);
    z-index: 1;
}

.part1 .text {
    position: relative;
    z-index: 2;
    background: url('http://dummy-images.com/nature/dummy-1024x576-Waterfalls.jpg');
    background-position: center center;
    background-size: 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.part2 {
    color: rgba(255, 255, 255, 0.5);
    z-index: 3;
    clip-path: polygon(400px 0px, 100% 0px, 100% 100%, 400px 100%);
}
<div class="example">
  <div class="part1"><span class="text">Stack<br>Overflow</span></div>
  <div class="part2"><span class="text">Stack<br>Overflow</span></div>
 </div>
 

更新: 我发现初始版本的文本背景未对齐。更新版本修复了此问题,但代价很小:.text 元素 需要 具有 width: 100%,因为它允许对齐背景。如果需要额外对齐文本,则需要添加一些 padding