【问题标题】:DIV "background-image" not stretched over entire DIV when using "background-size : 100% 100%"使用“背景尺寸:100% 100%”时,DIV“背景图像”未延伸到整个 DIV
【发布时间】:2019-01-13 17:18:49
【问题描述】:

在我的网站上,我正在构建一个自定义 HSV Color picker。 我决定不使用渐变,而是选择将在 HSV 滑块中使用的 .SVG 渐变图像。

我在将该图像适配到我的 DIV 的背景中时遇到问题。

Here's an example。 该图像在 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;
}

我该如何解决这个问题?

感谢所有帮助!

【问题讨论】:

  • 能否将 phvue.svg 上传到 imgur 并发送 html?
  • 是的,当然,我看不出它可以为您提供什么帮助,但如果您只是追求图像,您可以从over here 下载它。
  • 这可能与 svg 有关。如果您将 pvhue.svg 转换为 jpg 或其他内容,它应该可以工作。喜欢here
  • 发现,在将 .SVG 转换为 .PNG 后一切正常。讨厌直到今天对向量的支持如此有限,尤其是因为它们的扩展性如此之好!如果您想发布官方答案,我会接受它作为解决方案。干杯!

标签: javascript html css


【解决方案1】:

SVG 在 Edge 中仍然存在问题。因此,如果您不需要矢量图像,我建议使用老式 .png 或 .jpg 图像。

查看工作示例:

/* 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>

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 谢谢,我已经在父 DIV 中定义了这两个,但我仍然尝试过......不幸的是,它不起作用
    【解决方案3】:

    试试background-size: coverbackground-size: container。希望能解决你的问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-21
    • 2011-09-27
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    相关资源
    最近更新 更多