【问题标题】:Using (-webkit-)backdrop-filter on transparant header在透明标题上使用 (-webkit-)backdrop-filter
【发布时间】:2019-12-04 04:51:52
【问题描述】:

我想在文本部分透明(使用 rgba)的透明标题上使用 (-webkit-)backdrop-filter 应用背景过滤器。但是,这样做会将过滤器应用于文本的(方形)背景,而不是将其应用于仅文本本身后面的背景。

您可以在下面找到我当前使用的代码。

如果您想演示此代码,请记住将background-image: url("images.png"); 链接到实际图像。另请记住,backdrop-filter 仅适用于 Edge、Chrome(76 及更高版本,启用标志时的早期版本)和 Safari(使用 -webkit- 供应商前缀)。

如您所见,我还使用content 根据屏幕大小将附加文本添加到标题。尽管答案不一定要与此结合使用,但我们将不胜感激。

<div id="header">
  <h1>Drake</h1>
</div>

<style>
#header {
  height: 100vh;
  width: 100%;
  background-image: url("images.png");
  background-repeat: no-repeat;
  background-position: left;
  background-attachment: fixed;
  background-size: cover;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  margin: 0;
}

#header h1 {
  backdrop-filter: blur(20px) saturate(130%) brightness(300%);
  color: rgba(255, 255, 255, 0.3);
  font-size: calc(75px + 5vw);
  margin: 0;
}

#header h1:after {
  content: " Dragon";
  white-space: pre;
}

@media (max-width:750px) {
  #header h1:after {
    content: " D.";
    white-space: pre;
  }
}

@media (max-width:450px) {
  #header h1:after {
    content: none;
    white-space: pre;
  }
}
</style>

我想要达到的效果可以在 Apple 的网站上看到。更具体地说,关于他们即将推出的“街机”服务的页面。在此页面上,副标题具有动态模糊效果。

https://i.imgur.com/aRChGko.png (https://www.apple.com/apple-arcade/)

另一方面,我使用的代码并没有实现这种漂亮的模糊效果。它不仅模糊了文本本身,还模糊了文本的背景。

https://i.imgur.com/wfS5vNQ.png (https://jsfiddle.net/pfe39avr/2/)

【问题讨论】:

    标签: css image


    【解决方案1】:

    来自 CSS-Tricks 的 Chris Coyier 写了一篇关于如何做到这一点的文章:https://css-tricks.com/a-glassy-and-classy-text-effect/。下面是一个例子。

    <video src="https://css-tricks-post-videos.s3.us-east-1.amazonaws.com/Universe%20-%2013100.mp4" controls muted autoplay loop></video>
    
    <h1 class="headline">
      <span class="visually-hidden">Awesome Headline</span>
      <svg aria-hidden="true" id="lockup-headline-mask" class="headline lockup-headline-mask visually-hidden">
        <clipPath id="lockup-headline-mask-path">
          <text dominant-baseline="hanging" text-anchor="middle" x="50%" y="0em" dy="0.125em">Awesome Headline</text>
        </clipPath>
      </svg>
    </h1>
    
    <style>
    video {
      object-fit: cover;
      width: 100vw;
      height: 100vh;
      position: fixed;
      top: 0;
      left: 0;
    }
    
    body {
      height: 100vh;
      margin: 0;
      display: grid;
      place-items: center;
      text-align: center;
    }
    h1 {
      position: relative;
      color: white;
    }
    .headline {
      width: 100%;
      font: 8vw system-ui, sans-serif;
      font-weight: 900;
      height: 150px;
    }
    @supports (backdrop-filter: blur(12px)) {
      .visually-hidden {
        position: absolute;
        top: -9999px;
        left: -9999px;
      }
      h1 {
        backdrop-filter: blur(12px);
        background: rgba(white, 0.2);
        clip-path: url(#lockup-headline-mask-path);
      }
    }
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 2020-03-27
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多