【发布时间】:2018-03-07 00:43:29
【问题描述】:
所以我正在制作一个网站,我希望元素的背景模糊,但我不希望元素中的文本像现在一样模糊。有没有办法做到这一点而不必使用已经完成的图像? - 搜索引擎优化
你可以在下面的sn-p中看到我当前的一些代码:
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 16px;
box-shadow: inset 0 0 0 1000px rgba(0,0,0,.1);
height: 100%;
margin: 0;
padding: 0;
background: url('http://www.crossroadsaugusta.org/wp-content/uploads/2016/02/1418-56c10c706fcbb.jpg') fixed no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
main {
width: 800px;
margin: auto;
}
#welcome {
color: #fff;
width: 580px;
margin: 100px auto;
font-size: 110%;
border-radius: 25px;
border: #fff solid 1px;
margin-top: 50px;
box-shadow: inset 0 0 0 1000px rgba(0,0,0,.2);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
z-index: 1;
position: relative;
}
#welcome p {
z-index: 999;
margin: 10px;
}
<body>
<main role="main">
<header id="welcome">
<p>Content in here</p>
</header>
</main>
</body>
更新
好的,我自己解决了这个问题!也许我的问题不够清楚。
我想将父级模糊为一个段落(在本例中为标题标签),而不是模糊段落中的文本。所以模糊的父(标题)后面的所有元素也会变得模糊 - 在这种情况下是背景图像。我想出了如何自己完成这项工作,请参阅下面的 sn-p:
重要提示:背景图片必须是离模糊元素最近的父级(这里body是header的父级),否则模糊效果不起作用。
body {
background: url('https://www.planwallpaper.com/static/images/6944150-abstract-colors-wallpaper.jpg') fixed no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
margin: 0;
padding: 0;
}
header {
border-radius: 25px;
position: relative;
margin: 100px auto;
width: 500px;
background: inherit;
overflow: hidden;
}
header::before {
content: "";
position: absolute;
left: 0;
width: 100%;
height: 100%;
background: inherit;
background-attachment: fixed;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
header::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.25)
}
header h1, p {
margin: 20px 10px;
color: #fff;
position: relative;
z-index: 1;
}
<body>
<header>
<h1>
Whoo it's working!
</h1>
<p>this is also blurring the background</p>
</header>
</body>
【问题讨论】:
-
她是一篇类似的帖子,可能会对您有所帮助。 stackoverflow.com/questions/22406478/…
-
@Mx。这不是我的问题。在那里,他希望图像模糊,并且仅在涉及图像时才有效。我特别询问了如何在不使用图像的情况下做到这一点。