简体   繁体   English

使用“background-size : 100% 100%”时,DIV“background-image”没有在整个DIV上拉伸

[英]DIV "background-image" not stretched over entire DIV when using "background-size : 100% 100%"

On my website I am building a custom HSV Color picker .在我的网站上,我正在构建一个自定义的HSV 颜色选择器 Instead of using Gradients I've decided to opt for a .SVG Gradient image that I will use in my HSV Slider.我决定选择一个 .SVG Gradient 图像,而不是使用 Gradients,我将在我的 HSV 滑块中使用它。

I am having a problem with the fitting of that Image into the Background of my DIV.我在将该图像拟合到我的 DIV 的背景中时遇到问题。

Here's an example .这是一个例子 The Image is fitted perfectly in both Mozilla Firefox and Internet Explorer, but in Edge it looks as if only the "height" is at a "100%", and the "width" is "auto" - Which it is not, at least not in the CSS:该图像在 Mozilla Firefox 和 Internet Explorer 中都非常适合,但在 Edge 中它看起来好像只有“高度”为“100%”,而“宽度”为“自动”——至少它不是不在 CSS 中:

#pvdivsliderhue {
position: absolute;
top: 10px;
left: 10px;
right: 10px;
width: auto;
height: 30px;
border-radius: 15px;
background-image: url('images/pvhue.svg');
background-size: 100% 100%;
background-color: green;
display: flex;
}

How would I go about solving this issue?我将如何解决这个问题?

Appreciate all the help!感谢所有的帮助!

SVG is still buggy in Edge. SVG 在 Edge 中仍然有问题。 Therefore, I advise to use old school .png or .jpg images if you don't require a vector image.因此,如果您不需要矢量图像,我建议使用旧式 .png 或 .jpg 图像。

Check out the working example:查看工作示例:

 /* Demo Styles */ .picker { height: 150px; width: 200px; position: relative; margin: 0 auto; background-color: #e9e9e9; } /* Hue Slider */ #pvdivsliderhue { position: absolute; top: 10px; left: 10px; right: 10px; width: auto; height: 30px; border-radius: 15px; background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Hue_alpha.png/900px-Hue_alpha.png'); background-size: 100% 100%; background-color: white; display: flex; }
 <div class="picker"> <div id="pvdivsliderhue"></div> </div>

Make the margins and padding 0使marginspadding 0

#pvdivsliderhue {
position: absolute;
top: 10px;
left: 10px;
right: 10px;
width: auto;
height: 30px;
border-radius: 15px;
background-image: url('images/pvhue.svg');
background-size: 100% 100%;
background-color: green;
display: flex;
margin :0;
padding :0
}

Try background-size: cover or background-size: container .尝试background-size: coverbackground-size: container I hope it will solve your problem.我希望它能解决你的问题。

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

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