【发布时间】: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/)
【问题讨论】: