html - SVG tspan 元素 + 字体系列样式?

标签 html css svg

我正在尝试在 svg 按钮内的 tspan 元素内指定字体系列。它似乎没有注册,我也找不到任何关于此的文档。我只找到了 svg 中文本元素的文档。我的无数次尝试都没有使文本与网站其余部分的风格相匹配。我需要它才能使用来自 Google 的 Raleway 字体的精简版。

HTML

<svg viewbox="0 0 86 20" version="1.1" baseProfile="full" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
  <g>
    <path id="thisID" d="M 80 5 A 100 100 0 0 0 22.2 27.2 L 37.58 42.58 A 80 80 0 0 1 80 27.2 Z"></path>
    <text font-family:"Raleway:thin" fill="gold">
        <defs>
    <style type="text/css">@import url('https://fonts.googleapis.com/css?family=Raleway:thin');</style>
</defs>
         <textPath style="font-size:6pt;" xlink:href="#thisID" startOffset="63%" >
            <tspan dy="-6">Home</tspan>
      </textPath>
    </text>
  </g>
</svg>

新的尝试

嗯,我尝试使用下面的方法但没有成功。我在这里缺少什么?

<svg viewbox="0 0 86 20" version="1.1" baseProfile="full" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
          <style type="text/css">
        <![CDATA[   

  @import url('https://fonts.googleapis.com/css?family=Raleway:thin');
              {font-family:Raleway}

             ]]> 
  </style>
  <g>
    <path onclick="window.location='index.html';" id="thisID" d="M 80 5 A 100 100 0 0 0 22.2 27.2 L 37.58 42.58 A 80 80 0 0 1 80 27.2 Z"></path>
    <text font-family:"Raleway:thin" fill="gold">
         <textPath style="font-size:6pt;" xlink:href="#thisID" startOffset="63%" >
            <tspan dy="-6">Home</tspan>
      </textPath>
    </text>
  </g>
</svg>

最佳答案

您忘记声明字体系列。

<svg viewbox="0 0 86 20" version="1.1" baseProfile="full" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
   <style type="text/css">
        <![CDATA[   
  
  @import url('https://fonts.googleapis.com/css?family=Raleway:thin');
     text{font-family:Raleway}
     
             ]]> 
  </style>
  <g>
    <path id="thisID" d="M 80 5 A 100 100 0 0 0 22.2 27.2 L 37.58 42.58 A 80 80 0 0 1 80 27.2 Z"></path>
    <text font-family:"Raleway:thin" fill="gold">
<textPath style="font-size:6pt;" xlink:href="#thisID" startOffset="63%" >
            <tspan dy="-6">Home</tspan>
      </textPath>
    </text>
  </g>
</svg>

关于html - SVG tspan 元素 + 字体系列样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52936240/

相关文章:

jquery - 延迟出现在滚动条上

svg - 使用 GOB 的 Rebol 3 文本渲染问题

css - 无缝 SVG 循环

javascript - 背景图像不显示在移动设备上但显示在桌面上

php - 由于下拉脚本,动态下拉列表不起作用

javascript - 如何使用 jQuery 使图像显示在另一个图像之上

javascript - 无法使用 Backbone js使用自定义选择框

javascript - getCurrentPosition() 在 Firefox 中不起作用

html - 菜单问题

html - 小 svg 推到容器外