简体   繁体   English

css背景图像泄漏

[英]css background-image leak

This a WavyBar component that is made of a div with 3 background images.这是一个由带有 3 个背景图像的 div 组成的 WavyBar 组件。 The photo and 1 wavy white image at the top and another at the bottom on the top of a photo.照片和顶部的一张波浪形白色图像和照片顶部的底部的另一张。 That creates the wavy effect.这会产生波浪效果。

silver line on the top and bottom of the page页面顶部和底部的银线

As you can see on this image, there is a silver line on the top and bottom of this div, which is where the background photo is leaking outside of the div.正如你在这张图片上看到的,这个 div 的顶部和底部有一条银色的线,这是背景照片泄漏到 div 之外的地方。

The css used is the following:使用的css如下:

 background-image: url(2de1e10e83bb3f12dc8bfeb1818ee536.png), url(eeb31e00f15749916d5fd9d3ab2b8f10.png), url(f03c768d84f5d17e39ba033692433d0f.png);
    background-repeat: repeat-x, repeat-x, no-repeat;
    background-position: left top, left bottom, center center;
    background-size: auto, auto, cover;

adding these styles, kinda solved the problem, but created a white line on the top of the div添加这些样式,有点解决了问题,但在 div 顶部创建了一条白线

  padding: 1px 0;
  background-clip: content-box;

https://cloud.githubusercontent.com/assets/1951007/20140914/fe52e0c0-a674-11e6-944e-f16a6791659c.png https://cloud.githubusercontent.com/assets/1951007/20140914/fe52e0c0-a674-11e6-944e-f16a6791659c.png

Already tried box-sizing: with all values已经试过 box-sizing: with all values

Got into similar issue.陷入了类似的问题。 The background-color set for an image was leaking from top and bottom, even after playing around with margin, padding and box-sizing.图像的背景颜色设置从顶部和底部泄漏,即使在使用边距、填充和框大小调整之后也是如此。

Finally below solution worked for me.最后下面的解决方案对我有用。 You need to wrap the image in a Div element with height same(or lower than) as that of the image.您需要将图像包装在高度与图像高度相同(或低于)的 Div 元素中。 And push the image slightly to the top.并将图像稍微推到顶部。

.image{
    position: relative;
    top: -4px;
}

.parent{
    height: 240px; // keep it fix or use css calc() function
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM