SVG image is not cropped in IE9

左心房为你撑大大i 提交于 2019-12-19 05:36:11

问题


The following code:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Test.</title> 
    </head> 
    <body> 
        <div style="border: solid 1px black; height:100px; width:100px">
            <svg height="100" width="100" viewbox="00 0 100 100">
                <path id="map1" d="M210 10 L90 10 L90 90 " fill="red"/>
            </svg>
        </div>
</html>

JSFiddle: http://jsfiddle.net/HRsvX/

In Chrome and FF4 displays div with border and part of image that is INSIDE of SVG-object. Everything outside of the svg is not drawn.

IE9 displays WHOLE SVG-image. Is it a feature or a bug? Is there any way to cut the 'outbounding' part of image?

Does Raphael framework handle such case correctly?


回答1:


Edit: In light of my new understanding of the spec, I must correct myself below.

The default style required by the spec for elements in the svg namespace is:

svg, symbol, image, marker, pattern, foreignObject { overflow: hidden }
svg { width:attr(width); height:attr(height) }

per http://www.w3.org/TR/SVG/styling.html#UAStyleSheet

So, if you want IE9 to conform you can use:

svg:not(:root) { overflow: hidden; }

As suggested here and here.

The following is true if the default overflow: hidden is overridden:

According to the SVG Spec, SVG handles overflow like any other element when contained within a document that is using CSS. Items inside of the element overflow unless overflow: hidden or overflow:scroll if they exceed the size of the parent.

In your example, I see it as the path exceeds the viewbox defined on the svg element. Since the default overflow is visible, the path will "bleed" beyond the svg element's boundries. Additionally, it bleeds beyond the svg element's parent boundries, etc.



来源:https://stackoverflow.com/questions/5971320/svg-image-is-not-cropped-in-ie9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!