How to make filter Blur pick up the whole element. Prevent Blur from ending before the end of the element background

Asked

Viewed 268 times

5

I have a div who is with filter:blur(), but I noticed that the blur means it is inside the element. What I mean is that when you reach the box-model boundary the image of background begins to disappear before the edge, giving the impression that the background does not occupy the whole element.

inserir a descrição da imagem aqui

Notice the image above, see that the image is already disappearing before it even reaches the edge.

Notice the code that the two .box has the same size, and see how the blur does not complete the entire content. Is there any way to fix this problem?

div {float:left}
.box {
  width: 300px;
  height: 300px;
  background-image: url(https://placecage.com/300/300);
  filter: blur(5px);
}
.box2 {
  width: 300px;
  height: 300px;
  background-color: red;
}
<div class="box"></div>
<div class="box2"></div>

The intention is for the box to look like this, with 100% of the background content with blur

inserir a descrição da imagem aqui

1 answer

4


When you apply Blur to div, I don’t see how to prevent the edges from being blurred. One way is to insert the background image into a child element (a span, for example) and apply overflow: hidden in div. So the background image will not extrapolate the area of div:

.box {
   position: relative;
   width: 300px;
   height: 300px;
   overflow: hidden;
   background-color: blue;
}

.box span{
   display: inline-block;
   width: 100%;
   height: 100%;
   position: absolute;
   top: 0;
   left: 0;
   z-index: 0;
   background-image: url(https://placecage.com/300/300);
   filter: blur(5px);
   transform: scale(1.07);
}
<div class="box"><span></span></div>

  • Sam I think the way is maybe, but it’s not cool yet, see that by putting a BG color, there is still a contamination of the background color on the edge of the image http://prntscr.com/mzltxl there is still some adjustment in this code that can improve this problem?

  • I don’t understand :D... if you put a background-color, you say?

  • No no, I’m actually saying that Blur is still affecting the image edge. If you put a color on the body vc will see that this color is visible below the image, the Blur continues to "eat" a piece into the background of the element, note the second image of the question, see that the Blur fully picks up

  • Then I would have to slightly enlarge the image with Transform: Scale (I edited the answer)

  • Now I do! I had tried it with a margin:-5px; and tb had worked, but with Scale it might be even better, because the rendering might have helped the GPU, I can’t remember if the filter itself already activates the GPU... Anyway thanks! Tomorrow I accept pq hj already hit the haha ceiling :D

  • I just read here, Point of reply accepted is not taxed!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.