简体   繁体   English

在ie11中发生SVG问题

[英]SVG issues in ie11

I have a div that has it's height set to 320 pixels, then it's child is set to 100% width of that. 我有一个div,其高度设置为320像素,然后它的子设置为100%的宽度。 The child of that is a SVG file which I set the width to 200% of the container. 那个孩子是一个SVG文件,我将宽度设置为容器的200%。 In chrome and firefox that works fine, I get a nice image like this: 在chrome和firefox工作正常,我得到一个像这样的好图像:

在此输入图像描述

The HTML looks like this: HTML看起来像这样:

<div class="kit-template ng-isolate-scope front">
    <div class="svg-document ng-scope">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 259.5 131.4" enable-background="new 0 0 259.5 131.4" xml:space="preserve" class="ng-scope">
            <!-- Removed for brevity -->
        </svg>
    </div>
</div>

and the CSS/SASS looks like this: CSS / SASS看起来像这样:

.kit-template {
    overflow: hidden;
    position: relative;   
    height: 320px;

    .svg-document {  
        width: 100%;   
        overflow: hidden;
        margin: 0 auto;
        /*position: absolute;
        bottom: 0;*/

        svg {
            width: 200%;

            path, polyline, polygon, rect {
                cursor: pointer;
            }
        }
    }
}

Like I said, this works fine in both Chrome, Firefox and IE Edge. 就像我说的,这适用于Chrome,Firefox和IE Edge。 But in IE11 I get this: 但是在IE11中,我得到了这个:

在此输入图像描述

And if I inspect the element, I can see that the SVG looks like it has padding left and right on it, but I can assure you it doesn't. 如果我检查元素,我可以看到SVG看起来左右有填充,但我可以向你保证它没有。

Does anyone know why this is happening and how I can fix it? 有谁知道为什么会这样,以及我如何解决它?

Update 1 更新1

I have created a very simple version on codepen so you can see the issue. 我在codepen上创建了一个非常简单的版本,因此您可以看到问题。 Here it is: 这里是:

http://codepen.io/r3plica/pen/Kdypwe http://codepen.io/r3plica/pen/Kdypwe

View that in chrome, firefox, Edge and then IE11. 在chrome,firefox,Edge和IE11中查看。 You will see that only IE11 has the issue. 你会看到只有IE11才有问题。

What you can do is add the height="320" attribute to your SVG tag. 您可以做的是将height="320"属性添加到SVG标记。 So IE can render correctly. 因此IE可以正确呈现。 I believe IE11 is thrown off by using width 200% in your CSS. 我相信在CSS中使用宽度为200%的IE11会被抛弃。 But since xml:space="preserve" is the default, setting only the height will keep the proportions of your SVG jacket. 但由于xml:space="preserve"是默认设置,因此仅设置高度将保持SVG夹克的比例。

Test codepen example in IE11: 测试IE11中的codepen示例:

http://codepen.io/jonathan/pen/MarvEm http://codepen.io/jonathan/pen/MarvEm

<svg height="320" viewBox="0 0 248.2 142.8" enable-background="new 0 0 248.2 142.8" xml:space="preserve">

Also remove the XML namespace tag since it is not needed inside an HTML page. 还要删除XML命名空间标记,因为HTML页面中不需要它。 And you can also remove some of the SVG attributes like version , xmlns , xmlns:xlink , x , and y , since those are not needed as well. 您还可以删除一些SVG属性,如versionxmlnsxmlns:xlinkxy ,因为这些属性也不需要。

I was having SVG image display issue in IE11. 我在IE11中遇到了SVG图像显示问题。 The issue was inner svg image was having width and height mentioned. 问题是内部svg图像有宽度和高度提到。 Due to this it was failing to scale properly on IE11 and it was working fine on IE edge, chrome, firefox very fine. 由于这一点,它无法在IE11上正确扩展,它在IE边缘,chrome,firefox工作得很好。

<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120" viewBox="0 0 120 120">

To fix the issue I removed width="120" height="120" and its working fine. 为了解决这个问题,我删除了width =“120”height =“120”并且工作正常。 When I observed svg image was having width="120" height="120" viewBox="0 0 120 120" but in IE11 it was only showing width="120" height="120" . 当我观察到svg图像具有width =“120”height =“120”viewBox =“0 0 120 120”但是在IE11中它仅显示width =“120”height =“120”

output was: 输出是:

<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120">

在此输入图像描述

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

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