简体   繁体   English

SVG位置:IE 11中的绝对位置

[英]SVG position:absolute in IE 11

of I have an SVG object placed in a container. 我有一个放置在容器中的SVG对象。 It has the following CSS on its class. 它的类上有以下CSS。

.container{
    position: relative;
}

.svgObj{
    position: absolute;
    top: 0;
    left: 0;
    width: 2em;
    height: 2em;
}

So, the problem is that the svg doesn't end up in 0:0 of the container but rather more like in 200px south of that. 所以,问题是svg不会以容器的0:0结束,而更像是在200px以南。

The queer thing is that if I substiute the SVG tag for a DIV with the same class, it displays exactly where I want it to. 奇怪的是,如果我为具有相同类的DIV替换SVG标签,它会准确显示我想要的位置。

The problem is only apparent in IE (only tried 11, but likely there in earlier versions as well). 问题只在IE中显而易见(仅尝试了11,但在早期版本中也可能存在)。 Well, fwiw the problem is also visible in Minori. 嗯,这个问题在Minori中也很明显。 Works fine in Safari, Chrome, FF, Opera, well the bigs, except IE. 适用于Safari,Chrome,FF,Opera,以及除IE以外的大人物。

Any ideas are most welcome. 任何想法都是最受欢迎的。

The HTML code looks like so HTML代码看起来像这样

<div class="container">
<svg class="svgObject" data-x="0" data-y="0" data-text="My Obj"  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <a id="h-72417" href="#">
        <path d="M12 4a8 0z"></path>
        <path d="M12 4a8 0-16z"></path>
    </a>
</svg>
</div>

Never mind the path values, I shortened them here to save space. 别介意路径值,我在这里缩短它们以节省空间。 It shouldn't matter. 没关系。 The data attributes aren't relevant either. 数据属性也不相关。 As stated, just switching SVG for DIV and adding a "hello" instead of the paths makes it work as expected. 如上所述,只需切换SVG for DIV并添加“hello”而不是路径使其按预期工作。

Thanks. 谢谢。

Thanks for answering this ceindeg , even after the fact. 感谢你回答这个ceindeg ,即使事实之后。

For anyone else who's having this problem, an even better solution than the preserveAspectRatio attribute is to just simply make sure you have the width and height set inside the main SVG tag. 对于遇到此问题的任何其他人来说,比preserveAspectRatio属性更好的解决方案就是确保在主SVG标记内设置widthheight Most browsers don't need them, but IE is different (of course). 大多数浏览器不需要它们,但IE是不同的(当然)。

I know this is an old question, but I came across it as I was searching for an answer to this issue myself. 我知道这是一个老问题,但是当我在寻找这个问题的答案时,我遇到了它。 The solution that worked for me was to add preserveAspectRatio="xMinYMin meet" to the tag. 对我preserveAspectRatio="xMinYMin meet"的解决方案是在标签中添加preserveAspectRatio="xMinYMin meet" This essentially makes the SVG responsive and shifts the contents to the top left of the SVG container. 这实质上使SVG响应并将内容移动到SVG容器的左上角。

I found the answer here: http://thenewcode.com/744/Make-SVG-Responsive 我在这里找到了答案: http//thenewcode.com/744/Make-SVG-Responsive

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

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