html - svg 在 firefox 和 IE 中的问题

标签 html css svg

我的网站上有 svg,它在 chrome 中运行良好,但当我尝试在 Firefox 上检查它时,我认为它超出了框架放大范围。我是几个月前开始编码的设计师。这是 chrome 和 Firefox 的图像。

在 Chrome 中:

in Chrome this is how it looks

在 Firefox 中:

in firefox it looks like this

这是我使用的代码片段

svg {
    display: block;
    font: 10.5em 'Arial';
    width: 960px;
    height: 300px;
    margin: 0 auto;
}

.text-copy {
    fill: none;
    stroke: white;
    stroke-dasharray: 6% 29%;
    stroke-width: 5px;
    stroke-dashoffset: 0%;
    animation: stroke-offset 5.5s infinite linear;
}

.text-copy:nth-child(1){
    stroke: #4D163D;
    animation-delay: -1s;
}

.text-copy:nth-child(2){
    stroke: #840037;
    animation-delay: -2s;
}

.text-copy:nth-child(3){
    stroke: #BD0034;
    animation-delay: -3s;
}

.text-copy:nth-child(4){
    stroke: #BD0034;
    animation-delay: -4s;
}

.text-copy:nth-child(5){
    stroke: #FDB731;
    animation-delay: -5s;
}
@keyframes stroke-offset{
    100% {stroke-dashoffset: -35%;}
}

@media (min-width:768px){
    svg{
        width: 750px;
        height: 300px;
        margin: 0 auto;
    }
}
@media (max-width:767px){
    svg{
        font: 6.5em 'Arial';
        width: 100%;
        height: 300px;
        margin: 0 auto;
    }
    .text-copy {
        fill: none;
        stroke: white;
        stroke-dasharray: 6% 29%;
        stroke-width: 3px;
        stroke-dashoffset: 0%;
        animation: stroke-offset 5.5s infinite linear;
    }
}

.text-center1{
  color:rgba(255,255,255,0.8);
  text-align: center;
  font-size: 48px ;
  margin-top:40px;
}
@media (max-width:992px){
  .text-centre1{
    font-size:30px;
  }
}
<svg>
    <symbol id="s-text">
      <text text-anchor="middle" x="50%" y="80%">Digital</text>
    </symbol>
    <g class = "g-ants">
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
    </g>
</svg>

最佳答案

这似乎是 Firefox 中的一个错误。

如果您申请 em基于字体大小的 <svg>并在 <symbol> 中包含文本然后在 Firefox 中,<text>元素认为字体应该是当前字体大小 10.5em 的 10.5 倍。换句话说,字体大小成倍增加并最终达到 110.25em。

简单的解决方案是移动 font规则<text>埃克门特。

text {
  font: 10.5em 'Arial';
}

svg {
    display: block;
    width: 960px;
    height: 300px;
    margin: 0 auto;
}

text {
    font: 10.5em 'Arial';
}

.text-copy {
    fill: none;
    stroke: white;
    stroke-dasharray: 6% 29%;
    stroke-width: 5px;
    stroke-dashoffset: 0%;
    animation: stroke-offset 5.5s infinite linear;
}

.text-copy:nth-child(1){
    stroke: #4D163D;
    animation-delay: -1s;
}

.text-copy:nth-child(2){
    stroke: #840037;
    animation-delay: -2s;
}

.text-copy:nth-child(3){
    stroke: #BD0034;
    animation-delay: -3s;
}

.text-copy:nth-child(4){
    stroke: #BD0034;
    animation-delay: -4s;
}

.text-copy:nth-child(5){
    stroke: #FDB731;
    animation-delay: -5s;
}
@keyframes stroke-offset{
    100% {stroke-dashoffset: -35%;}
}

@media (min-width:768px){
    svg{
        width: 750px;
        height: 300px;
        margin: 0 auto;
    }
}
@media (max-width:767px){
    svg{
        width: 100%;
        height: 300px;
        margin: 0 auto;
    }
    text {
        font: 6.5em 'Arial';
    }
    .text-copy {
        fill: none;
        stroke: white;
        stroke-dasharray: 6% 29%;
        stroke-width: 3px;
        stroke-dashoffset: 0%;
        animation: stroke-offset 5.5s infinite linear;
    }
}

.text-center1{
  color:rgba(255,255,255,0.8);
  text-align: center;
  font-size: 48px ;
  margin-top:40px;
}
@media (max-width:992px){
  .text-centre1{
    font-size:30px;
  }
}
<svg>
    <symbol id="s-text">
      <text text-anchor="middle" x="50%" y="80%">Digital</text>
    </symbol>
    <g class = "g-ants">
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
      <use xlink:href="#s-text" class="text-copy"></use>
    </g>
</svg>

关于html - svg 在 firefox 和 IE 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45817403/

相关文章:

javascript - 为什么 .html() 不适用于使用 jquery 的 SVG 选择器?

html - 使用表格而不是 div 会给最终用户带来什么真正的问题?

javascript - 如何删除数据表上的文本 "entries"

html - 固定菜单,但正文覆盖了菜单

javascript - 如何取消html表格中先前的输入

html - 有没有办法让 svg 元素可以在 html 页面上突出显示?

html - 如何制作自动换行到下一行的div

javascript - Facebook 页面插件无法在网站上正确显示

html - 为元素站点定义根文件夹

javascript - 使用 d3.js 绘制旋转和翻转的叠瓦 block