如何调整SVG文字

时间:2019-04-11 01:01:17

标签: css css3 svg text kerning

我在网页上有一些SVG文本,我想精挑细选几个字母-我该怎么做?使用HTML,我只需将字母包装在<span>标记中,并使用position属性将其移动,但这不适用于SVG。

例如,如何在提供的代码段中移动字母“ o”?

任何帮助都会很棒。

body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100%;
  height: 300vh;
  margin: 0;
  padding: 0;
  font-family: arial-black;
}


text {
  font-size: 2rem;
}
<svg class="git-svg" width="500" height="400" viewBox="0 0 500 400">
    <text x="15" y="26" fill="#000">How We Work</text>
</svg>

codepen:https://codepen.io/emilychews/pen/PgmoOE

2 个答案:

答案 0 :(得分:1)

SVG具有tspan标记,您应该将其用于在文本元素中精确定位文本:

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/tspan

答案 1 :(得分:0)

您只能尝试属性letter-spacing

body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100%;
  height: 300vh;
  margin: 0;
  padding: 0;
  font-family: arial-black;
}


text {
  font-size: 2rem;
  letter-spacing: 2px;
}
<svg class="git-svg" width="500" height="400" viewBox="0 0 500 400">
    <text x="15" y="26" fill="#000">How We Work</text>
</svg>