How to blur(css) div without blur child element [duplicate] - html

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 2 years ago.
.content {
float: left;
width: 100%;
background-image: url('images/zwemmen.png');
height: 501px;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px);
-ms-filter: blur(3px);
filter: blur(3px);
}
.opacity {
background-color: rgba(5, 98, 127, 0.9);
height: 100%;
overflow: hidden;
}
.info {
float: left;
margin: 100px 0px 0px 30px;
width: 410px;
}
<div class="content">
<div class="opacity">
<div class="image">
<img src="images/zwemmen.png" alt="" />
</div>
<div class="info">
a div wih all sort of information
</div>
</div>
</div>
If I do not want to blur the button, what do I need to do?

When using the blur or opacity property, it is not possible to ignore the child element. If you apply either of those properties to parent element, it will automatically apply to child elements too.
There is an alternate solution: create two elements inside your parent div – one div for the background and another div for the contents. Set position:relative on the parent div and set position:absolute; top:0px; right:0px; bottom:0px; left:0px; (or set height/width to 100%) to the child element for the background. Using this method, the content div will not be affected by properties on the background.
Example:
#parent_div {
position: relative;
height: 100px;
width: 100px;
}
#background {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: red;
filter: blur(3px);
z-index: -1;
}
<div id="parent_div">
<div id="background"></div>
<div id="textarea">My Text</div>
</div>
If you see the background masking over the content, then use the z-index property to send the background behind the second content div.

How to disable blur on child element?
.enableBlur>* {
filter: blur(1.2px);
}
.disableBlur {
filter: blur(0);
}
<div class="enableBlur">
<hr>
qqqqq<br>
<span>qqqqq</span><br>
<hr class="disableBlur">
<div>aaaaa</div>
<div>bbbbb</div>
<div class="disableBlur">DDDDD</div>
<hr>
<img src="https://lh5.googleusercontent.com/-n8FG4f09-ug/AAAAAAAAAAI/AAAAAAAACmA/ldtxmWX1SyY/photo.jpg?sz=48">
<img class="disableBlur" src="https://lh5.googleusercontent.com/-n8FG4f09-ug/AAAAAAAAAAI/AAAAAAAACmA/ldtxmWX1SyY/photo.jpg?sz=48">
</div>

My solution seems a bit simpler but may have some compatibility issues. I just used backdrop-filter with the blur filter.
backdrop-filter: blur(2px);

Just create two divisions and adjust their z-indexes and margins such that the division you want to blur lies below the division you want to appear on top.
PS: Don't create division inside a division cause the child inherits the parent's properties.
#forblur {
height: 200px;
width: 200px;
background-color: blue;
margin: auto;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px) -ms-filter: blur(3px);
filter: blur(3px);
z-index: -1;
}
#on-top-container {
margin: auto;
margin-top: -200px;
text-align: center;
height: 200px;
width: 200px;
z-index: 10;
}
<div id="forblur">
</div>
<div id="on-top-container">
<p>TEXT</p>
</div>

Related

Problem with css scale transform and filter blur

I have problem on Chrome browser while combining two properties: filter: blur(15px) and transform: scale3d(1.2,1.2,1).
I have two images, one over another. Image on higer layer is blurred, but it's edges got transparent when I applied that filter, so I added overflow:hidden to parent div, and scaled up image. I expected to see just opaque part of image.
It works as expected on Firefox and Opera, however on Chrome and MS Edge browsers not. How to fix this?
#images-box{
position: relative;
width: 500px;
height: 280px;
overflow:hidden;
}
.image{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('https://images.unsplash.com/photo-1558389157-a986a38f3431?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80');
background-size: cover;
background-position: 50% 50%;
}
.image.blured{
-webkit-filter: blur(14px);
filter: blur(14px);
z-index: 2;
-webkit-transform: scale3d(1.2,1.2,1);
transform: scale3d(1.2,1.2,1);
}
<div id="images-box">
<div class="image"></div>
<div class="image blured"></div>
</div>
Changing scale3d(1.2,1.2,1) to scale(1.2) helped me on Chrome 86.0.4240.198.

Vuetify.js - Adding blur and transparent styles to v-card [duplicate]

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 2 years ago.
.content {
float: left;
width: 100%;
background-image: url('images/zwemmen.png');
height: 501px;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px);
-ms-filter: blur(3px);
filter: blur(3px);
}
.opacity {
background-color: rgba(5, 98, 127, 0.9);
height: 100%;
overflow: hidden;
}
.info {
float: left;
margin: 100px 0px 0px 30px;
width: 410px;
}
<div class="content">
<div class="opacity">
<div class="image">
<img src="images/zwemmen.png" alt="" />
</div>
<div class="info">
a div wih all sort of information
</div>
</div>
</div>
If I do not want to blur the button, what do I need to do?
When using the blur or opacity property, it is not possible to ignore the child element. If you apply either of those properties to parent element, it will automatically apply to child elements too.
There is an alternate solution: create two elements inside your parent div – one div for the background and another div for the contents. Set position:relative on the parent div and set position:absolute; top:0px; right:0px; bottom:0px; left:0px; (or set height/width to 100%) to the child element for the background. Using this method, the content div will not be affected by properties on the background.
Example:
#parent_div {
position: relative;
height: 100px;
width: 100px;
}
#background {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: red;
filter: blur(3px);
z-index: -1;
}
<div id="parent_div">
<div id="background"></div>
<div id="textarea">My Text</div>
</div>
If you see the background masking over the content, then use the z-index property to send the background behind the second content div.
How to disable blur on child element?
.enableBlur>* {
filter: blur(1.2px);
}
.disableBlur {
filter: blur(0);
}
<div class="enableBlur">
<hr>
qqqqq<br>
<span>qqqqq</span><br>
<hr class="disableBlur">
<div>aaaaa</div>
<div>bbbbb</div>
<div class="disableBlur">DDDDD</div>
<hr>
<img src="https://lh5.googleusercontent.com/-n8FG4f09-ug/AAAAAAAAAAI/AAAAAAAACmA/ldtxmWX1SyY/photo.jpg?sz=48">
<img class="disableBlur" src="https://lh5.googleusercontent.com/-n8FG4f09-ug/AAAAAAAAAAI/AAAAAAAACmA/ldtxmWX1SyY/photo.jpg?sz=48">
</div>
My solution seems a bit simpler but may have some compatibility issues. I just used backdrop-filter with the blur filter.
backdrop-filter: blur(2px);
Just create two divisions and adjust their z-indexes and margins such that the division you want to blur lies below the division you want to appear on top.
PS: Don't create division inside a division cause the child inherits the parent's properties.
#forblur {
height: 200px;
width: 200px;
background-color: blue;
margin: auto;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px) -ms-filter: blur(3px);
filter: blur(3px);
z-index: -1;
}
#on-top-container {
margin: auto;
margin-top: -200px;
text-align: center;
height: 200px;
width: 200px;
z-index: 10;
}
<div id="forblur">
</div>
<div id="on-top-container">
<p>TEXT</p>
</div>

color image inside grayscale(100%) container

I have a div with a background-image and i'm using a filter to display it in black and white (filter: grayscale(100%);). I'm now trying to place a color icon inside that div. Tried to set the icon to grayscale(0%), but this does not appear to work.
Here is an example:
#a1, #a2 {
background-image: url(http://ndrichardson.com/blog/wp-content/uploads/2012/04/colorpsychology.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
#a1 {
height: 250px;
width: 250px;
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
position: relative;
}
#a2 {
height: 50px;
width: 50px;
-webkit-filter: grayscale(0%);
filter: grayscale(0%);
position: absolute;
top: 0px;
right: 0px;
}
<div id="a1"><!-- << this should be black and white -->
<div id="a2"><!-- << this should be color -->
</div>
</div>
Is there a way to do this without creating an additional div to hold the background image? The real code is much more complex, that's why I would like to avoid the extra div(s), if possible.
Yes of course, you should use ::before and ::after pseudo-elements:
#a1 {
height: 250px;
width: 250px;
position: relative;
}
#a1:after, #a1:before {
content: '';
background-image: url(http://ndrichardson.com/blog/wp-content/uploads/2012/04/colorpsychology.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
position: absolute;
}
#a1:before {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
width: 100%;
height: 100%;
}
#a1:after {
height: 50px;
width: 50px;
top: 0px;
right: 0px;
}
<div id="a1"></div>
DEMO on JSFiddle
It's not possible to have color inside a container with filter: grayscale(100%).
See the the filter property in the spec (emphasis mine):
A computed value of other than none results in the creation of a
stacking context the same way that CSS opacity does. All
the elements descendants are rendered together as a group with the
filter effect applied to the group as a whole.
So yes, you will have to separate the contents with the filter from the contents without it.
This doesn't necessarily mean you need additional wrappers in your HTML, as Hiszpan proposes you can also use pseudo-elements.

Translucent effect to section of webpage [duplicate]

This question already has answers here:
Opacity of background-color, but not the text [duplicate]
(5 answers)
Closed 7 years ago.
I have a background image for my webpage and I have this
HTML:
<body>
<div class="front">
<p>Hello World</p>
</div>
</body>
CSS:
.front{
background-color:silver;
height:200px;
width:200px;
}
The width & height of div is 200px,200px.I want the area covered by the div element to be translucent ie. showing the blur background, but the text that div contains should be clear as well. How do I do that?
You need a rgba background:
background-color: rgba(192,192,192,0.5);
Colors can be defined in the Red-green-blue-alpha model (RGBa) using
the rgba() functional notation. RGBa extends the RGB color model to
include the alpha channel, allowing specification of the opacity of a
color. a means opacity: 0=transparent; 1=opaque;
You could simply add opacity: 0.5; to your css class.
You can use the rgba for the background image since adding opacity would apply it for the text in the div also.
background-color: rgba(192,192,192,0.5);
but this is not supported in IE.
So you can have a transparent background image created and applied using background-image property.
you can use opacity for the background-image and use before Selector to remain the opacity of the text:
like this:
.front {
z-index: 1;
}
.front:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-image: url("http://webneel.com/wallpaper/sites/default/files/images/01-2014/23-animation-wallpaper.preview.jpg");
background-repeat: no-repeat;
background-size: 100%;
opacity: 0.4;
filter: alpha(opacity=40);
height: 200px;
width: 200px;
}
.font > p {
z-index: -1;
opacity: 1;
filter: alpha(opacity=100);
}
<div class="front">
<p>Hello World</p>
</div>
JSFIDDLE DEMO
try this css :
.front{
background-color:silver;
height:200px;
width:200px;
opacity: 0.4;
}
Increase or decrease opacity according to your choice.
Using opacity in CSS is the easiest way.
Well, little out of the box, you can really blur your image if you try a little different mark-up.
Here it goes
.front{
background-color:silver;
height:200px;
width:200px;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px);
-ms-filter: blur(3px);
filter: blur(3px);
z-index:0;
}
.back{
position: absolute;
top: 0;
}
<body>
<div class="front"></div>
<div class="back">
<p>Hello World</p>
</div>
</body>

CSS blur property only for background-image

I am trying to apply the CSS blur property only to the background-image of with id="home", but it also reflects in children class too. My HTML code is:
<section id="home">
<div class="home">
<h1>ncats is an innovative</h1>
</div>
</section>
My CSS code is:
#home{
display: block;
background:url(../images/2.jpg) no-repeat;
background-size: cover;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
width: 100%;
height: 1080px;
}
.home{
text-align:center;
}
I'm trying to get an output like in the below link:
http://codepen.io/akademy/pen/FlkzB
But my output is like this, instead: http://codepen.io/anon/pen/yyEZOb
I got your Codepen to work with the following CSS:
#home:before{
content: ""; /* CHANGE HERE! */
position: absolute; /* CHANGE HERE! */
z-index: -1; /* CHANGE HERE! */
display: block;
background:url('http://666a658c624a3c03a6b2-25cda059d975d2f318c03e90bcf17c40.r92.cf1.rackcdn.com/unsplash_527bf56961712_1.JPG') no-repeat;
background-size: cover;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
width: 100%;
height: 1080px;
}
.home{
text-align:center;
z-index: 0; /* CHANGE HERE! */
}
Add the ':before' pseudo-element to specify that content be inserted before the element selected (#home).
Setting position to absolute and changing the z-indices are important here since we have to do some rearranging of the elements.
More info about :before pseudo-element
https://developer.mozilla.org/en-US/docs/Web/CSS/::before
More info about z-index:
http://www.w3schools.com/cssref/pr_pos_z-index.asp
To get the output like the codepen you shared, you have to use the same technique and use a pseudo element like :before or :after.
Just change your CSS as follows:
#home:before{
content:'';
display: block;
background:url('http://666a658c624a3c03a6b2-25cda059d975d2f318c03e90bcf17c40.r92.cf1.rackcdn.com/unsplash_527bf56961712_1.JPG') no-repeat;
background-size: cover;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
width: 100%;
height: 1080px;
position: absolute;
top: 0;
left: 0;
z-index:-1;
}
Perhaps you could use the opacity related property instead of the webkit-filter option:
#home{
display: block;
background:url('imageurl') no-repeat;
background-size: cover;
filter: alpha(opacity=30);
-moz-opacity: 0.3;
-khtml-opacity: 0.3;
opacity: 0.3;
width: 100%;
height: 1080px;
}
Actually you need to understand the block structure of HTML div. Whatever you apply to a parent element or parent division also get applied to the child.
So if this is your code
<div class="parent">
Hi...
<div class="child">
i am child
</div>
</div>
Now if you apply css filter:blur property to parent class it will too effect to the child class, as the parent class/div block contains the child class/div block inside it. So whatever you give to parent also get adopted by child.
But there is still a way this is how you can do : JSFiddle.
Explanation: There is one div with child as span and the other span as separate element. This div is given blur so it's child would also get affected, but the separate span is not because it's not the child of that div.
HTML
<div class="bg">
<span class="inner">
<h1>Hey i am normal text above the Background, and i am "Blur" ! </h1>
</span>
</div>
<span class="outer">
<h1>Hey i am normal text above the Background, and i am not "Blur" ! </h1>
</span>
CSS
html, body {
color:white;
margin:0%;
position:relative;
background:black;
}
.bg {
margin:0%;
background-image:url(http://upload.wikimedia.org/wikipedia/commons/1/12/Sling-Sat_removing_space_debris.png);
background-repeat:no-repeat;
background-size:cover;
height:100%;
width:100%;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
z-index:-1;
}
.inner {
z-index:0;
display:block;
width:100%;
height:100%;
position:fixed;
top:0%;
overflow:auto;
text-align:center;
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-o-filter: blur(0px);
-ms-filter: blur(0px);
filter: blur(0px);
}
.outer {
z-index:0;
display:block;
width:100%;
height:100%;
position:fixed;
top:0%;
overflow:auto;
text-align:center;
padding-top:50px;
}
For future readers (and present ones, who don’t particularly care about cross-browser support): there is a CSS mechanism that does exactly this.
In the Filter Effects spec, filters are defined to also work as a functional notation, accepting an image + a list of filters. The syntax looks like this:
.El {
background-image: filter(url(myImage.jpg), blur(5px));
}
...where the second argument to the filter function accepts a list of filters (the same as the filter property).
Sadly, only Safari has implemented it so far—it was released as -webkit-filter() in Safari 9, but had some serious bugs so they didn't even announce that it was supported. It's fixed in WebKit since, and due to be released in the next version of Safari (iOS 9.3/Desktop Safari 9.1).