【问题标题】:How to remove white border from blur background image如何从模糊背景图像中删除白色边框
【发布时间】:2015-05-06 09:56:01
【问题描述】:

如何去除背景图片中的白色模糊边框。

<div class="background-image"></div> 

CSS,我尝试添加边距:-10px,但它不起作用

.background-image {
  background: no-repeat center center fixed; 
   background-image: url('http://www.hdpaperz.com/wallpaper/original/windows-8-wallpapers-2560x1600-2311_1.jpg') ; 
  background-size: cover;
  display: block;
  height: 100%;
  left: -5px;
  top:-5px;
  bottom:-5px;
  position: fixed;
  right: -5px;
  z-index: 1;
  margin:0px auto;
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;

 }

http://jsfiddle.net/maio/8wq132nd/1/

【问题讨论】:

  • 只是删除所有供应商前缀的模糊属性?例如(-webkit-filter:模糊(5px);-moz-filter:模糊(5px);-o-filter:模糊(5px);-ms-filter:模糊(5px);过滤器:模糊(5px);)我'不确定这是不是问题?
  • 希望此链接对您有所帮助,[如何将 CSS 3 模糊滤镜应用到我使用 background-image 设置的背景图像][1] [1]:stackoverflow.com/questions/20039765/…

标签: html css blur


【解决方案1】:

使用 SVG-Blur 滤镜。

filter: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a' x='0' y='0' width='1' height='1' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='4' result='b'/%3E%3CfeMorphology operator='dilate' radius='4'/%3E %3CfeMerge%3E%3CfeMergeNode/%3E%3CfeMergeNode in='b'/%3E%3C/feMerge%3E%3C/filter%3E %3C/svg%3E#a");

“stdDeviation”是你的强度。

source

【讨论】:

    【解决方案2】:

    最新答案 (2021)

    您可以通过在覆盖元素上使用backdrop-filter 来实现此效果。

    .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;
    }
    &lt;div class="blurred"&gt;&lt;/div&gt;

    请记住,这不是 IE 中的 supported,它只有在明确启用后才能在 firefox 中使用。

    【讨论】:

    • 这一点的绝妙之处在于,如果您只想模糊背景图像的一半高度,只需在 ::before 类上设置 height: 50%
    • 非常感谢!!这就像魅力!这个答案应该被接受!
    • 在 Firefox 中不起作用。 Firefox 默认不支持背景过滤器。我们必须手动启用
    • @minigeek 是的,我已经在我的回答中说明了这一点。
    【解决方案3】:

    如果白边是body的背景色引起的,在body上应用margin: 0;,因为margin默认不为0;

    【讨论】:

      【解决方案4】:

      这是我根据@Prime 的回答确定的一个函数。

      为了使其工作,图像必须位于具有图像的widthheight&lt;div/&gt; 内(显式设置)。

          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`
            }
          }
      

      【讨论】:

      • 但是在firefox中广告一个白色边框很烦人(必须在body标签上添加背景颜色才能修复)
      【解决方案5】:

      这对我有用: 添加了两个固定图像,一个 z=-1,另一个 z=0,模糊了第一个。

      【讨论】:

      • 这种方法的折衷是在模糊的顶层周围有一个新边界,该边界由原始图像的清晰版本组成。但所有方法似乎都需要权衡取舍!
      【解决方案6】:

      最简单的方法是添加 transform: scale(1.1)。 试试看here

      #overlay {
       position: fixed;
       left: 22.5em;
       top: 3em;
       height: 75%;
       width: 50%;
       background: url("https://s-media-cacheak0.pinimg.com/originals/ae/b4/c5/aeb4c53cab2b550187644af503a0f17e.png");
       background-size: cover;
       filter: blur(9px);
       transform: scale(1.1); 
      }
      

      【讨论】:

      • 认为这会将图像缩放得更大,如果您希望图像保持相同大小并且只想删除白色边框,则不是很完美
      • 它还为 webkit 浏览器中的溢出创建了一个滚动条,即使使用溢出也无法删除:隐藏。见:stackoverflow.com/questions/16687023/…
      • 我这样做了,但在 Android WebView 上有滚动。即使我添加了溢出:隐藏。我有一种感觉是因为我的背景比 html 元素大
      • 您能解释一下这个故障的根本原因吗?
      • 我将overflow: hidden 添加到父div 以摆脱transform: scale(1.1) 创建的滚动条。
      【解决方案7】:

      我在容器中添加了负边距:margin: -5px

      【讨论】:

        【解决方案8】:

        我添加了溢出、填充甚至边距,但问题仍然没有解决。所以我试图在div之间给出图像标签。问题解决了。

        <div class="background-image">
        <img src="http://www.hdpaperz.com/wallpaper/original/windows-8-wallpapers-2560x1600-2311_1.jpg" width="100%" height="100%"/>
        </div>
        

        css

         .background-image {
          background: no-repeat center center fixed; 
          background-size: cover;
          display: block;
          left: -5px;
          top:-5px;
          bottom:-5px;
          position: fixed;
          right: -5px;
          z-index: 1;
          -webkit-filter: blur(5px);
          -moz-filter: blur(5px);
          -o-filter: blur(5px);
          -ms-filter: blur(5px);
          filter: blur(5px);
          -webkit-background-size: cover;
          -moz-background-size: cover;
          -o-background-size: cover;
          margin:-5px;
        
         }
        

        js 小提琴

        http://jsfiddle.net/2pgdttLh/

        【讨论】:

          【解决方案9】:
          padding: 10px 10px;
          

          在你的 CSS 中添加这个来移除底部的白色模糊边框

          【讨论】:

          • 你可以像这样白那个速记:padding: 10px;
          猜你喜欢
          • 1970-01-01
          • 2010-11-02
          • 1970-01-01
          • 1970-01-01
          • 2023-03-28
          • 2018-07-01
          • 2019-06-13
          • 1970-01-01
          相关资源
          最近更新 更多