Backdrop-filter: Blur not working on a position absolute element

Viewed 2053

I'm trying to make a tooltip with a glass effect using the backdrop-filter: blur, except that the filter doesn't seem to work on elements in absolute position. I imagine this is because the item has gone out of the document flow so don't recognize the background, but there might be workarounds to fix it.

image: the filter does not act on elements in absolute position

2 Answers

I found out that elements with transparent background get incorrectly blurred. I wonder if the parent of this element is one that has transparent background.

In my case I had my body transparent which made blur not work, and solved it with:

body {
  background-color: white;
}

I can give you a sample which was given by a user in stack overflow. I have given the sample code below Hope it helps:

CSS:

body,
main::before {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/80625/tree.jpg) 0 / cover fixed;
}

main {
  margin: 100px auto;
  position: relative;
  padding: 10px 5px;
  background: hsla(0, 0%, 100%, .3);
  font-size: 20px;
  font-family: 'Lora', serif;
  line-height: 1.5;
  border-radius: 10px;
  width: 60%;
  box-shadow: 5px 3px 30px black;
  overflow: hidden;
}

main::before {
  content: '';
  margin: -35px;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  filter: blur(20px);
  z-index: -1;
}

HTML:

<main>
  <blockquote>"The more often we see the things around us &#45; even the beautiful and wonderful things &#45; the more they become invisible to us. That is why we often take for granted the beauty of this world: the flowers, the trees, the birds, the clouds &#45;
    even those we love. Because we see things so often, we see them less and less."
    <footer>&mdash;
      <cite>
        Joseph B. Wirthlin
      </cite>
    </footer>
  </blockquote>
</main>
Related