css - 在透明 header 上使用 (-webkit-)backdrop-filter

标签 css image

我想在文本部分透明(使用 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的网站上看到。更具体地说,是关于他们即将推出的“Arcade”服务的页面。在此页面上,副标题具有动态模糊效果。

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

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

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

最佳答案

来自 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>

关于css - 在透明 header 上使用 (-webkit-)backdrop-filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57209942/

相关文章:

css - Twitter Bootstrap 2 流体布局应适合屏幕(+ 可滚动区域)

HTML 元素位置与 CSS

java - 通过 BufferedImage 从文件路径加载图像

java - 启用通过resteasy将图像作为Fileoutputstream发送

python - 如何检测图像之间的偏移

html - 我试图在实际页脚上方放置一个小的 'About Us' 页脚,但似乎无法让它出现在页面上

html - 如何在主 div 中组织 2 个 div 以使其始终静止?

javascript - 如何使用 JavaScript 找到滚动条的中间点?

ios - ios中如何根据方向改变图像位置?

asp.net - ASP.NET 中图像的 ImgUrl 属性的预处理器指令存在问题