【发布时间】:2014-08-24 00:31:52
【问题描述】:
我已经尝试了以下问题中的解决方案,但似乎都不起作用:
- Scaling/Resizing SVG in an HTML
- How to scale SVG properly and responsively in HTML5?
- Best practice for using SVGs, regarding height and width?
在最后一个问题中,高度和宽度都在 CSS 中指定,但我只想指定其中一个尺寸。例如,目前我的 CSS 中有一个 max-height 来控制图像的高度。
这是我的代码:
HTML
<a href='#schedule'>
<img src='images/calendar.svg' alt='' role='presentation' class='nav-item-icon'>
<span class='nav-item-text'>Schedule</span>
</a>
CSS
.navigation-main a {
padding: 0.5rem 0;
text-decoration: none;
display: block;
width: 100%;
height: 100%;
}
.nav-item-icon {
max-height: 1.5em;
vertical-align: middle;
}
.nav-item-text {
display: inline-block;
vertical-align: middle;
padding-left: 0.5em;
}
SVG
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="82.7272727273px" height="100px" viewBox="0 0 91.59 110.063"
enable-background="new 0 0 91.59 110.063" xml:space="preserve">
<!-- codes -->
</svg>
结果
Internet Explorer 11
Firefox 和 Chrome
我尝试删除 SVG 的高度和宽度属性,但这会使所有浏览器中的 SVG 成为父元素的 100% 宽度,除非我在 CSS 中指定宽度。内联 SVG 并没有什么不同。
在 JavaScript 中可能有一种方法可以通过获取计算的高度并手动设置宽度来做到这一点,但我不想诉诸这样的技巧。有没有办法让图像在 Internet Explorer 中正确缩放?
【问题讨论】:
标签: css internet-explorer svg scale