简体   繁体   English

CSS定位问题仅在野生动物园

[英]css positioning issue only in safari

I have texts on svg on a div loadingMessage that want it to be appear in middle no matter how large or small is the window opened, it works well in Chrome, Firefox, and IE. 我在div loadingMessage上的svg上有文本,无论窗口打开的大小如何,它都希望出现在中间,它在Chrome,Firefox和IE中都可以很好地工作。 But for safari, it is off to right side. 但是对于野生动物园,它位于右侧。 I was wondering why and how to solve this. 我想知道为什么以及如何解决这个问题。 Below are pictures of running it on safari and other browsers. 以下是在Safari和其他浏览器上运行它的图片。 在此处输入图片说明 在此处输入图片说明

My code for the svg is: 我的SVG代码是:

 var message = d3.select("#loadingMessage")
            .append("svg")
            .attr("id", "erase")
            .attr("width", 500)
            .attr("height", 100)
            .append("text")
            .text("Why this does not work on safari")
            .attr("x", 250)
            .attr("y", 55)
            .attr("fill", 'royalBlue')
            .attr("font-size", 20)
            .attr("font-weight", "bold")
            .attr("text-anchor", "middle")
            .attr("font-family", "Sans-serif");

and my code for css positioning is: 我的css定位代码是:

#loadingMessage{
position: absolute;
top: 55%;
left: 50%;
transform: translate(-50%, -50%);}

Thank you. 谢谢。

Safari does not support unprefixed CSS transforms . Safari不支持未前缀的CSS转换 Even once the Mac version does, the Windows version still won't, because it hasn't been updated since 2012. Testing in Safari on Windows is basically a waste of time because no one uses the Windows version, and it doesn't give you an accurate idea of what Mac Safari users will see. 即使Mac版本使用过,Windows版本也不会使用,因为自2012年以来就没有进行过更新。在Windows上的Safari中进行测试基本上是在浪费时间,因为没有人使用Windows版本,并且没有您可以准确了解Mac Safari用户将看到的内容。

To fix the issue, add a prefixed version of transform : 要解决此问题,请添加transform的前缀版本:

#loadingMessage{
    position: absolute;
    top: 55%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}

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

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