So I am making a site where I want the background of an element to be blurred, While I don’t want the text within the element to get blurred, like it currently does. Is there a way to do this without having to use an image where everything is already done? – for SEO
You can see some of my current code in the snippet below:
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>
Update
Okay I solved the problem myself! maybe I was not clear enough in my question.
I wanted to blur the parent to a paragraph(In this case a header tag), without blurring the text withing the paragraph. So that all elements behind the blurred parent(header) would get blurred as well – in this case a background image. I figured out how to make this work myself, see how in the snippet below:
Important notice: The background image has to be the closest parent to the blurred element(Here the body is parent to the header), otherwise the blur effect won’t work.
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>
4
Answers
Place a div where you want the blur effect and add
filter:blur
to the div class.Please see the demo here
Filters
are the css3 level property and work only in modern browsers.filter
works likeopacity
it affect the element and any children. So, use a::before
pseudo-element and apply the blur to that.JSfiddle Demo
This is the right way to solve your problem, but you have to use rbg value instead of hexcode.
Not sure if you know about backdrop filter but it allows you to apply effects to anything behind a div and they are working on adding support to Chrome and Firefox but it is currently only supported by Safari. Here’s the code anyway as I’m not sure when it will be supported.