Make a div transparent like a blurred mirror - css

I want to make a div background transparent so i used this css
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-ms-filter: blur(1px);
-o-filter: blur(1px);
filter: blur(1px);
also see this fiddle: http://jsfiddle.net/LUy3W/
I want only the div to be blurred but all the content in that div is also being blurred. How to make only that background div blur and make its content visible like normal text?
any thoughts? please help.

This can now be accomplished with a single line of CSS using the backdrop-filter property (along with many other filter effects), however browser support at the time of writing is very poor, so make sure to provide a fallback version for unsupported browsers as well as the -webkit- prefixed version for now.
.wrapper {
height: 400px;
width: 400px;
background-image: url('https://i.imgur.com/iAgdW.jpg');
background-size: cover;
}
.inner {
background-color: rgba(255, 0, 0, 0.5);
-webkit-backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
padding: 50px;
}
<div class="wrapper">
<div class="inner">my text</div>
</div>
The rendered output in supported browsers will look like:

The content can't be inside the blurred div, so use a sibling element instead:
HTML
<div class="wrapper">
<div class="content">my text</div>
</div>
CSS
.wrapper {
height:400px;
width:400px;
position: relative;
}
.wrapper::before{
width:100%;
height:100%;
position: absolute;
background-image:url('https://i.imgur.com/iAgdW.jpg');
background-size:cover;
-webkit-filter: blur(4px);
-moz-filter: blur(4px);
-ms-filter: blur(4px);
-o-filter: blur(4px);
filter: blur(4px);
}
.content{
position: absolute;
background-color:red;
}
Demo fiddle

For example.
The html
<div class="div-Blur">
<div class="div-inside-blur">
</div>
</div>
The css
.div-Blur {
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-ms-filter: blur(1px);
-o-filter: blur(1px);
filter: blur(1px);
}
edit: try this plse
.div-inside-blur {
background: blue;
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
}

Related

How to make blur effect without white light?

I use the following CSS property to set blur effect:
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
It makes div element blur, but I see white light at the corners of block, how can I make blur effect without them?
The only way to remove the blurred edges in a pure CSS way is by zooming the element a little bit then clipping the edges with overflow: hidden added to the container:
.container {
overflow: hidden;
border: 1px solid red;
display: inline-block;
}
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
transform-origin: 50%;
transform: scale(1.3);
}
<div class="container">
<div class="blur">
<img src="http://lorempixel.com/700/300" alt="">
</div>
</div>
jsFiddle: https://jsfiddle.net/azizn/7v0mtfyn/

Blurring image resulting in blur taking in elements from outside the container / div [duplicate]

This question already has answers here:
Defined Edges With CSS3 Filter Blur
(17 answers)
Closed 8 years ago.
I have this very simple pen of a blurred background image.
HTML
<div> </div>
CSS
div {
background: url(http://s15.postimg.org/4elomwgbv/luxvitae.jpg) no-repeat;
width: 1500px;
height: 1000px;
-webkit-filter: blur(25px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
body{
background-color: green;
}
Now what happens is that the blur actually takes into account the surrounding or lying below elements, which i don't like
It basically shows the background where there should be no background, and blurs the image into the background. What I want is to see: no green overlapping into my div container. My div should only contain the image that is blurred.
someone got an idea?
This is because a blur also feathers the edge. You could layer the blurred image on top of the image using a pseudo-element, although the edge won't be blurry for obvious reasons.
Example (click the "Full page" button):
.blurimg {
background: url(http://s15.postimg.org/4elomwgbv/luxvitae.jpg) no-repeat;
width: 1500px;
height: 1000px;
position: relative;
}
.blurimg:after {
content: '';
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: inherit;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
body{
background-color: green;
margin: 0;
}
<div class="blurimg"> </div>

css blur filter in Firefox giving shadow around the clipped area. why?

I am trying to create a blurred area within an image but am having some issues with firefox adding a shadow around the clip path for some reason?
Fiddle is here
CSS:
div {
position:absolute;
background:url(http://static.guim.co.uk/sys-images/Observer/Columnist/Columnists/2011/10/21/1319219972164/Oak-tree-in-field-007.jpg);
height:276px;
width:460px;
}
div:after {
background:inherit;
content:"";
width:inherit;
height:inherit;
position:inherit;
top:0px;
left:0px;
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'blur\'><feGaussianBlur stdDeviation=\'5\' /></filter></svg>#blur"); filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='5');
clip: rect(20px, 257px, 177px, 20px);
}
Please compare the link in Chrome (which looks great) and firefox (which has the shadow issue)
Thanks
I am not seeing the issue on my end in FF or Chrome.
They look identical to me (Larger Image):

How can I blur an image using css but keep the border straight?

I am trying to blur an image using CSS. I'm usig "blur" but I'm finding this also blurs the border. Is there a way to keep the border straight but blur the rest of the image?
http://www.inserthtml.com/2012/06/css-filters/
css
filter: filter(value);
-webkit-filter: filter(value);
-moz-filter: filter(value);
-o-filter: filter(value);
-ms-filter: filter(value);
Try something like this:
HTML:
<div id="container">
<img id="image" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Benz-velo.jpg/220px-Benz-velo.jpg">
</div>​
CSS:
#image{
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
margin:-1px;
padding:1px;
}
#container{
width:222px;
height:179px;
overflow:hidden;
}
The margin on the image seems to be required for some reason (at least in Chrome).
Also on jsfiddle: http://jsfiddle.net/jdwire/HUaBV/1/.
You will likely need to wrap that image in a block-level element and set its dimensions to match the image and add overflow: hidden.
Wrap a div around the image and size the div a few pixels smaller than the image is sized (otherwise the edge of the blur won't be cropped). Then put overflow:hidden on the div.
See the jsFiddle demo here.
Have a div with the border just enclose on it then blur the image.
css
div.container
{
border:2px solid #000000;
display:inline-block;
}
img.theimage
{
filter: filter(value);
-webkit-filter: filter(value);
-moz-filter: filter(value);
-o-filter: filter(value);
-ms-filter: filter(value);
}
html
<div class="container">
<img class="theimage" src="iamgesrc.jpg" />
</div>
To keep the edges sharp you can first move the image within it's container left and up the same amount of the blur—this will clean up the top/left edges. To sharpen the bottom/right edges reduce the width of the image's container by 2 * the blur amount.
#image {
filter: blur(5px);
-webkit-filter: blur(5px); /* support appears limited http://caniuse.com/#search=css%20filter%20effects */
margin-left: -5px; /* move the image negative x-blur distance */
margin-top: -5px; /* move the image negative y-blur distance */
}
#container {
/* actual image size is 220px * 177px */
width: 210px; /* subtract 2 * x-blur from width */
height: 167px; /* subtract 2 * y-blur from height */
overflow: hidden;
}
Joshua's Fiddle elaborated here: http://jsfiddle.net/3EHe9/

Defined Edges With CSS3 Filter Blur

I am blurring some images with this code
img {
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
}
The edges of the image get blurred too though. Is it possible to blur the image, while keeping the edges defined? Like an inset blur or something?
You could put it in a <div> with overflow: hidden; and set the <img> to margin: -5px -10px -10px -5px;.
Demo:
Output
CSS
img {
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
margin: -5px -10px -10px -5px;
}
div {
overflow: hidden;
}
​
HTML
<div><img src="http://placekitten.com/300" />​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​</div>​​​​​​​​​​​​
I was able to make this work with the
transform: scale(1.03);
Property applied on the image. For some reason, on Chrome, the other solutions provided wouldn't work if there was any relatively positioned parent element.
Check http://jsfiddle.net/ud5ya7jt/
This way the image will be slightly zoomed in by 3% and the edges will be cropped which shouldn't be a problem on a blurred image anyway. It worked well in my case because I was using a high res image as a background. Good luck!
I used -webkit-transform: translate3d(0, 0, 0); with overflow:hidden;.
DOM:
<div class="parent">
<img class="child" src="http://placekitten.com/100" />
</div>
CSS:
.parent {
width: 100px;
height: 100px;
overflow: hidden;
-webkit-transform: translate3d(0, 0, 0);
}
.child {
-webkit-filter: blur(10px);
}
DEMO: http://jsfiddle.net/DA5L4/18/
This technic works on Chrome34 and iOS7.1
Update
http://jsfiddle.net/DA5L4/50/
if you use latest version of Chrome, you don't need to use -webkit-transform: translate3d(0, 0, 0); hack. But it doesn't works on Safari(webkit).
You can also keep the whole video, you do not have to cut something away.
You can overlay inset shadows over the white-blurred edges.
This looks really nice as well :)
Just paste this code to your videos' parent:
.parent {
-webkit-box-shadow: inset 0 0 200px #000000;
-moz-box-shadow: inset 0 0 200px #000000;
box-shadow: inset 0 0 200px #000000;
}
Up-to-date answer (2021)
Use backdrop-filter instead! It blurs just like filter but without any edges, and without any compromises like resizing or scaling the image.
.blurred::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
backdrop-filter: blur(10px); /* apply the blur */
pointer-events: none; /* make the overlay click-through */
}
.blurred {
position: relative;
width: 500px;
height: 300px;
background: no-repeat center center;
background-image: url('https://besthqwallpapers.com/Uploads/26-5-2019/94041/thumb2-tesla-model-x-2019-exterior-front-view-new-gray-model-x.jpg');
background-size: cover;
}
<div class="blurred"></div>
Keep in mind that this is not supported in IE and it only works in firefox if it is explicitly enabled.
In the many situations where the IMG can be made position:absolute, you can use clip to hide the blurred edges--and the outer DIV is unnecessary.
img {
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
position: absolute;
clip: rect(5px,295px,295px;5px);
}
Having tackled this same problem myself today, I'd like to present a solution that (currently) works on the major browsers. Some of the other answers on this page did work once, but recent updates, whether it be browser or OS, have voided most/all of these answers.
The key is to place the image in a container, and to transform:scale that container out of it's overflow:hidden parent. Then, the blur gets applied to the img inside the container, instead of on the container itself.
Working Fiddle: https://jsfiddle.net/x2c6txk2/
HTML
<div class="container">
<div class="img-holder">
<img src="https://unsplash.it/500/300/?random">
</div>
</div>
CSS
.container {
width : 90%;
height : 400px;
margin : 50px 5%;
overflow : hidden;
position : relative;
}
.img-holder {
position : absolute;
left : 0;
top : 0;
bottom : 0;
right : 0;
transform : scale(1.2, 1.2);
}
.img-holder img {
width : 100%;
height : 100%;
-webkit-filter : blur(15px);
-moz-filter : blur(15px);
filter : blur(15px);
}
Insert the image inside a with position: relative; and overflow: hidden;
HTML
<div><img src="#"></div>
CSS
div {
position: relative;
overflow: hidden;
}
img {
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
}
This also works on variable sizes elements, like dynamic div's.
Just some hint to that accepted answer, if you are using position absolute, negative margins will not work, but you can still set the top, bottom, left and right to a negative value, and make the parent element overflow hidden.
The answer about adding clip to position absolute image has a problem if you don't know the image size.
You can stop the image from overlapping it's edges by clipping the image and applying a wrapper element which sets the blur effect to 0 pixels. This is how it looks like:
HTML
<div id="wrapper">
<div id="image"></div>
</div>
CSS
#wrapper {
width: 1024px;
height: 768px;
border: 1px solid black;
// 'blur(0px)' will prevent the wrapped image
// from overlapping the border
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
filter: blur(0px);
}
#wrapper #image {
width: 1024px;
height: 768px;
background-image: url("../images/cats.jpg");
background-size: cover;
-webkit-filter: blur(10px);
-moz-filter: blur(10px);
-ms-filter: blur(10px);
filter: blur(10px);
// Position 'absolute' is needed for clipping
position: absolute;
clip: rect(0px, 1024px, 768px, 0px);
}
The simplest way is just adding a transparent border to the div that contains the image and setting its display property to inline-block just like this:
CSS:
div{
margin: 2rem;
height: 100vh;
overflow: hidden;
display: inline-block;
border: 1px solid #00000000;
}
img {
-webkit-filter: blur(2rem);
filter: blur(2rem);
}
HTML
<div><img src='https://images.unsplash.com/photo-1557853197-aefb550b6fdc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=375&q=80' /></div>
Here's a codepen depicting the same:
https://codepen.io/arnavozil/pen/ExPYKNZ
If you are using background image, the best way I found is:
filter: blur(5px);
margin-top: -5px;
padding-bottom: 10px;
margin-left: -5px;
padding-right: 10px;
If all fails, You can choose to block this issue with a box-shadow effect.
Here's an example based on the question:
img {
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
box-shadow: 0 0 5px 20px #333; // <= Or colour you like.
}
This is of course not the most pleasant solution, but it should work great in some cases.
You can clip the image or the container, that way you can make sure nothing with overflow it.
div {
clip-path=polygon(0 0,100% 0, 100% 100%, 0 100%);
}
You can apply it to the image or you can use path or inset instead of polygon
You can try adding the border on an other element:
DOM:
<div><img src="#" /></div>
CSS:
div {
border: 1px solid black;
}
img {
filter: blur(5px);
}
I found that, in my case, I did not have to add a wrapper.
I just added -
margin: -1px;
or
margin: 1px; // any non-zero margin
overflow: hidden;
My blurred element was absolutely positioned.
Here is a solution I came up with keeps 100% of the image and no crop is needed:
Basically I mirror tile the image in 3x3 grid then blur everything and then zoom in at the center image effectively creating like a repeat edges when blurring in after effects, it a bit strange that css3 don't have like a repeat edges built in.
Link to the method / code:
How to blur an image using CSS3 without cropping or fading the edges?

Resources