如何在 CSS 中模糊文本背后的背景?

问题描述 投票:0回答:2

我正在尝试创建一个简单的小前端项目,我需要使一些文本可以从背景图像中辨别出来。

如何使文字背后的背景变得模糊?它只是模糊容器,我只想模糊实际文本后面。

我当前的文本代码:

.center h1 {
    font-size: 100px;
    font-style: italic;
    font-family: 'Montserrat', sans-serif;
    background: -webkit-linear-gradient(0deg,rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.25));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    backdrop-filter: blur(10px);
}

/* added by editor for deomnstration purpose */
body {
  background-image: url('https://upload.wikimedia.org/wikipedia/commons/5/5b/St_Mary%27s_Church%2C_Castle_Street_1.jpg');
  background-size: cover;
}
.center {
  position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -100%);
    text-align: center;
    width: max-content;
}
<div class="center">
<h1>GLUSH</h1>

<!-- Added by original poster for better running -->
</div>

事情的结局就是这样:

有什么办法可以做到这一点吗?我之前和

background-clip
一起工作过...

html css blur
2个回答
5
投票

只需使用

backdrop-filter
并根据您的喜好使用
blur
saturate
过滤器。
blur
明显模糊了背景,同时
saturate
赋予它更多“颜色深度”

h1 {
  backdrop-filter: blur(10px) saturate(70%);
}

/* to make the header only as wide as the content and centering it */

h1 {
  width: min-content;
  padding: 20px;
  margin: 0 auto;
}
  


/* added by editor for deomnstration purpose */

body {
  background-image: url('https://upload.wikimedia.org/wikipedia/commons/5/5b/St_Mary%27s_Church%2C_Castle_Street_1.jpg');
  background-size: cover;
}

h1 {
  font-size: 5em;
}
<h1>GLUSH</h1>


0
投票

您可以利用

[blur]
属性的
text-shadow
值来实现所需的效果:

some-element {
  text-shadow: [x-offset] [y-offset] [blur] [color];
}

就我而言,沙质背景图像上有白色文本,由于缺乏对比度而难以阅读。

因此,通过使用零偏移和带有深色阴影的慷慨模糊值,我能够使用以下方法获得不错的效果:

my-element {
  text-shadow: 0 0 0.15em #000000;
}
© www.soinside.com 2019 - 2024. All rights reserved.