css - 如何在 Firefox 和 Internet Explorer 中使 SVG 清晰

标签 css google-chrome internet-explorer firefox svg

当我使用 <svg>为了显示图标,它在谷歌浏览器中看起来非常清晰锐利。然而,当我在 Firefox 或 Internet Explorer 中打开 svg 时,图标看起来很模糊。

这些浏览器似乎将图标呈现为半像素。只有谷歌浏览器在这方面做得很好。

enter image description here

在所有浏览器中获得清晰的 svg 图标的最佳方法是什么? (我们想通过填充为图标着色:...所以使用背景图像或像素图形是没有选择的)

到目前为止我尝试过的: 我已经应用了 CSS 属性 shape-rendering .但是这个太脆了。

<svg width="16px" height="16px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
    <path fill="#231F20" d="M16,16H0V0h6.8l2,3H16V16z M1,15h14V7H1V15z M1,6h14V4H8.2l-2-3H1V6z"></path>
</svg>
<svg width="32px" height="32px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
    <path fill="#231F20" d="M16,16H0V0h6.8l2,3H16V16z M1,15h14V7H1V15z M1,6h14V4H8.2l-2-3H1V6z"></path>
</svg>

<button type="button" style="width: 42px; height: 42px;"><i style="background-image: none; pointer-events: none;">
<svg style="width: 24px; height: 24px;" viewBox="0 0 24 24" enable-background="new 0 0 24 24" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve">
	<rect y="19" fill="#231F20" width="24" height="2"></rect>
	<rect y="3" fill="#231F20" width="24" height="2"></rect>
	<rect y="11" fill="#231F20" width="24" height="2"></rect>
</svg>
</i></button>


<svg style="width: 24px; height: 24px;" viewBox="0 0 24 24" enable-background="new 0 0 24 24" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve">
	<rect y="19" fill="#231F20" width="24" height="2"></rect>
	<rect y="3" fill="#231F20" width="24" height="2"></rect>
	<rect y="11" fill="#231F20" width="24" height="2"></rect>
</svg>

最佳答案

Firefox 破解:

svg {
 transform: translateZ(0);
}

关于 IE: 可能的原因是当 svg 容器位于 31.5 之类的坐标(不完全在像素线上)时,IE 将以相同的方式在此容器中绘制 svg,有点偏离像素线。

关于css - 如何在 Firefox 和 Internet Explorer 中使 SVG 清晰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35579705/

相关文章:

Jquery 滑动切换中断

javascript - Bootstrap 折叠和隐藏覆盖不适用于匿名函数

css - 如何在 Vaadin 7 中水平对齐组件与 CSS 布局?

jquery - 使用 text 方法向样式元素添加 css 规则在 IE 中不起作用

javascript - IE 脚本错误/JQuery 循环

jquery - WP Sliding Bar Toggle无法关闭抽屉

visual-studio - 如何在 Visual Studio Blazor Wasm 应用程序调试期间停止 Chrome 缓存

javascript - 为什么 Object.prototype.hasOwnProperty.call(Number, "toString") 返回 false?

javascript - Google Chrome 标签页 ID 在标签页的生命周期内发生变化

javascript - 无法让我的 jquery slider 与 Internet Explorer 一起工作