简体   繁体   English

IE9中的SVG宽度

[英]SVG width in IE9

I have a SVG . 我有一个SVG In Firefox and Chrome the width:100% and height:100% is working well. 在Firefox和Chrome中, width:100%height:100%可以正常工作。 But in Internet Explorer 9 is not. 但是在Internet Explorer 9中却不是。

Somebody knows how to fix it? 有人知道如何解决?

Thanks. 谢谢。

UPDATE: 更新:

My really problem is putting this SVG into a table (the width is awful in IE9). 我真正的问题是将此SVG放入表格中 (IE9中的宽度太糟糕了)。 The <td> 's are dynamic, I can't set width for the container of the SVG. <td>是动态的,我无法为SVG的容器设置width

It's because the html, body, and div elements are collapsing down to the intrinsic height of the SVG. 这是因为html,body和div元素正在崩溃到SVG的固有高度。

To work around that, you can set the html, body, and div elements to 100% height: 要解决此问题,您可以将html,body和div元素设置为100%高度:

html, body, div { width: 100%; height: 100%; }

See http://jsfiddle.net/7Z8kg/2/ 参见http://jsfiddle.net/7Z8kg/2/


Update: 更新:

OK, as far as I can tell IE9 is failing to calculate a width and height on the SVG element, so it's falling back to the default for replaced elements (300×150px). 好的,据我所知IE9无法计算SVG元素的widthheight ,因此它已恢复为替换元素默认值 (300×150px)。 You're setting a height but not a width on the parent ( .ic3-svg-arrow ) so the SVG is still defaulting to 300px wide. 您要在父.ic3-svg-arrow上设置height而不是width.ic3-svg-arrow ),因此SVG仍默认为300px宽。

I've worked around it here using the Intrinsic Ratio trick : Essentially give the parent element an aspect ratio (in this case 1:1) and using absolute positioning to make the SVG fit that size. 我在这里使用了“固有比率”技巧解决了这个问题:本质上给父元素一个纵横比(在这种情况下为1:1),并使用绝对定位使SVG适应该大小。 This relies upon you knowing the aspect ratio in advance, but seems to work well for this problem: 这取决于您事先知道长宽比,但似乎可以很好地解决此问题:

/* Use padding to create a 1:1 aspect ratio */
.ic3-svg-arrow {
    height: 0;
    padding-bottom: 100%;
    position: relative;
}
/* Use positioning to make the SVG fit the ratio */
.ic3-svg-arrow svg {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

See http://jsfiddle.net/7Z8kg/15/ which looks the same to me across IE9, IE11, Firefox and Chrome. 请参阅http://jsfiddle.net/7Z8kg/15/ ,对于我来说,在IE9,IE11,Firefox和Chrome浏览器中,该外观都相同。

I took inspiration from this article, which has lots of useful SVG sizing tips . 我从本文中获得了启发, 该文章提供了许多有用的SVG尺寸调整技巧

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

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