html - Chrome - 在不保持比例的情况下拉伸(stretch)背景图像

标签 html css google-chrome background-image

我有以下代码:

.container {
  width: 1rem;
  height: 2rem;
  background-image: url(https://dl.dropboxusercontent.com/u/1142760/static/svg/triangle.svg);
  background-size: 100% 100%;
  border: 1px solid black;
}
<div class="container"></div>

我希望 div 的背景图像被拉伸(stretch)到所述 div 的完整 widthheight >.

Firefox 的行为符合预期:

the arrow is nicely stretched to the full width and height of the container, distorting the original image's aspect ratio

但是 Chrome 似乎有一个错误,它会以不同的方式解释 background-size:

enter image description here

您可以在 this fiddle 中看到实时结果

重新创建背景图像不是解决方案,因为有问题的 div 是可变的 height

这个 Chrome 错误是否有解决方法?

最佳答案

也许有人会找到这篇文章,但找不到正确的答案。 我发现在我的例子中,我必须向我的 svg 文件添加一个属性:

<svg preserveAspectRatio="none" ... 

关于html - Chrome - 在不保持比例的情况下拉伸(stretch)背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31556950/

相关文章:

html - 背景位置和不透明度

javascript - 如何在 Chrome 扩展中获取剪贴板数据?

javascript - window.onfocus 不会停止在 Chrome 中触发

css - md-sidenav 动画不在 IE 中禁用?

html - 为什么只有 firefox 在使用 PHP 时表现得像我想要的那样?

javascript - 如何重定向到 chrome 中的扩展页面?

javascript - jQuery 折叠隐藏另一个元素

html - 如何让字体光标位于顶部,文本对齐: top?

html - 我如何过滤angularjs中的选择值?

html - 使用 CSS3 动画将 div 从屏幕顶部移动到底部?