How to remove white border from blur background image

前端 未结 9 760
傲寒
傲寒 2020-12-28 17:23

How to remove the white blur border from the background image.

CSS, i tried adding marg

9条回答
  •  自闭症患者
    2020-12-28 18:23

    Here's a function I settled on based on @Prime 's answer.

    In order for it to work the image must be positioned inside a

    having the width and height of the image (explicitly set).

        function addBlur(style, radius) {
          return {
            ...style,
            // https://caniuse.com/#feat=css-filters
            filter: `blur(${radius}px)`,
            // Works around the white edges bug.
            // https://stackoverflow.com/questions/28870932/how-to-remove-white-border-from-blur-background-image
            width: `calc(100% + ${2 * radius}px)`,
            height: `calc(100% + ${2 * radius}px)`,
            marginLeft: `-${radius}px`,
            marginTop: `-${radius}px`
          }
        }
    

提交回复
热议问题