css - SVG 作为 IE 中的背景图像并带有缩放功能

标签 css internet-explorer svg

我将 SVG 用作背景图片:

<div class="buble"></div>

和 CSS:

.buble
{
  background-image: url(https://beta.creasoft.cz/Images/buble-small.svg);
  background-repeat: no-repeat;

  width: 48px;
  height: 48px;
}

在 IE 11 中显示并缩放(将缩放设置为 105% 或更多)时,它看起来很破:

enter image description here

在 Chrome 中运行良好。 有什么办法可以解决吗?

https://codepen.io/raptor/pen/WZoYBB

最佳答案

IE11 不支持 viewBoxwidthheight 属性缩放 SVG 图片明确规定。在您的情况下,您要提供 48px 的图像和 widthheight,IE11 不希望正确缩放。

要修复它,您可以只使用一个容器。您需要做的第一件事是构建容器来容纳您的 SVG。

<div id="container">
  <div class="buble"></div>
</div>

现在您需要定义容器,并将 width: 100% 添加到 .buble div 或 SVG。

#container {
  width: 48px;
  height: 48px;
}
.buble {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-image: url('https://beta.creasoft.cz/Images/buble-small-test.svg');
}

您可能还需要确保 heightwidth 已从实际 SVG 文件本身(如果包含)中删除。你可以结账 this GitHub repo有关 SVG + IE 的更多信息。

关于css - SVG 作为 IE 中的背景图像并带有缩放功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46399526/

相关文章:

css - SVG 动画 G 元素

html - 形状方形效果

javascript - 跨浏览器功能标识

javascript - 单击图片中的某些区域应该会出现边框

jquery - 浏览器会记住 session

html - CSS @page 规则 : How to preview in Internet Explorer

javascript - 如何使复选框显示/隐藏 SVG 内容

javascript - 带有鼠标事件的梯形 div

html - 顶部的 % 设置不起作用

javascript - 调整下拉菜单高度以显示更多选项(AngularJS Material )