简体   繁体   English

IE 11 中的 SVG 高度

[英]SVG height in IE 11

I have a complex HTML code that I simplified here :我有一个复杂的 HTML 代码,我在这里简化了:

<label class="FancyInput">
  <input type="text">
    <svg viewBox="0 0 10 18" class="FancyInputBorder">
        <path d="M-1000,12 L223.166144,12 C217.241379,12 217.899687,12 225.141066,12"></path>
    </svg>
    <svg viewBox="0 0 14 12" class="FancyInputCheck">
        <path d="M1 7 5.5 11 L13 1"></path>
    </svg>  
</label>

<style>
.FancyInputBorder {
    width:1200px;
    height:18px;
    display: inline;
}

.FancyInputCheck {
    width:14px;
    height:12px;
}
</style>

Basically the HTML doesn't render the same way in Chrome and IE 11. So I removed all non required code to illustrate the problem.基本上 HTML 在 Chrome 和 IE 11 中的呈现方式不同。所以我删除了所有不需要的代码来说明问题。

in Chrome FancyInputBorder has indeed the right height which is 18px but in IE 11 it doesn't.在 Chrome FancyInputBorder 中确实具有正确的高度,即 18px,但在 IE 11 中却没有。

Screen shot :截屏 :

在此处输入图片说明

Can anyone help please ?有人可以帮忙吗? Why IE 11 doesn't set the height of the SVG at 18 px as requested.为什么 IE 11 没有按照要求将 SVG 的高度设置为 18 像素。

Thanks Cheers谢谢干杯

Possible answer would be using the attribute viewbox and preserveAspectRatio .可能的答案是使用属性viewboxpreserveAspectRatio

<svg viewBox="0 0 1200 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMin slice">
    <defs></defs>
    <g>
        <path d="whatever you have here"></path>
    </g>
</svg>

It's also possible to set style on the svg tag => style="width:1200px;height:18px;"也可以在 svg 标签上设置样式 => style="width:1200px;height:18px;" but in my experience this can be left out in most cases.但根据我的经验,在大多数情况下可以忽略这一点。 In most cases, remove the width and height attributes on the svg tag if you have any.在大多数情况下,删除 svg 标签上的widthheight属性(如果有)。 Depending on your code using the svg code inline, in CSS or as an img src, things might be different.根据您使用内联 svg 代码、CSS 或 img src 的代码,情况可能会有所不同。

So a very general answer which can be reviewed, once you show some actual code that matters.因此,一旦您展示了一些重要的实际代码,就可以查看一个非常笼统的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM