How to blur background image of div, without blurring the remaining site or the content of the div

前端 未结 2 1425
旧时难觅i
旧时难觅i 2021-01-15 14:27

I\'m trying to figure out how to blur the background image of a div. The goal is to only blur the background image of the div and not the background of the page itself or th

2条回答
  •  悲哀的现实
    2021-01-15 15:04

    I have created a example using div, this includes a parent div,image and text. Now if I don't apply any position to elements present inside then they will align one after another, but to make image as background of div I have set it's position as absolute and using filter you can apply blur to the image and then using z-index align them i.e text and image. Hope this helps.

    The filter property provides graphical effects like blurring, sharpening, or color shifting an element. Filters are commonly used to adjust the rendering of images, backgrounds, and borders.

    div{
      width:200px;
      height:200px;
      overflow:hidden;
      position:relative;
    }
    div > img{
      width:auto;
      height:100%;
      z-index:1;
      top:0;
      left:0;
      position:absolute;
      filter:blur(10px);
    }
    div > p{
      text-align:center;
      top:60px;
      z-index:9;
      position:relative;
    }

    Demo text.Demo text.Demo text.Demo text.Demo text.

提交回复
热议问题