简体   繁体   English

SVG按钮内的文字?

[英]Text Inside an SVG Button?

I need to have text inside svg navigation buttons that will not affect the ability for the button to be used and will maintain the hover effects. 我需要在svg导航按钮中包含文本,这些文本不会影响按钮的使用能力并保持悬停效果。 The text also needs to follow the save curve as the button and be centered within the button. 文本还需要遵循保存曲线作为按钮,并在按钮内居中。 I have provided my HTML for reference. 我提供了HTML供参考。

The problem with my attempt is that it acts similar to placing absolute-positioned h or p elements over the svg path. 我的尝试的问题在于它的行为类似于在svg路径上放置绝对定位的h或p元素。 It interrupts the functionality and hover events since it is another element. 由于它是另一个元素,因此会中断功能和悬停事件。

 <svg viewbox="0 0 86 20" version="1.1" baseProfile="full" width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <g> <path 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 style="transform:rotate(-20deg);" x="0" y="40"><defs><path stroke="white" id="curve-text" d="M 0 15 A 80 80 0 0 1 80 27.2"></path></defs><textpath xlink:href="#curve-text" style="font-size:9pt;">Test</textpath></text> </g> </svg> 

I'm using the path #thisID as textPath reference. 我正在使用路径#thisID作为textPath参考。 I'm using startOffset to change the starting position of the text along the path. 我正在使用startOffset来更改文本沿路径的开始位置。

 <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 fill="gold"> <textPath xlink:href="#thisID" startOffset="63%" > <tspan dy="-6">test</tspan> </textPath> </text> </g> </svg> 

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

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