【问题标题】:Circular text around a circle image圆形图像周围的圆形文本
【发布时间】:2018-12-27 22:46:40
【问题描述】:

上下文:

试图将 SVG 路径文本放在圆形图像的顶部。
方形图片使用rounded-circle 进行四舍五入。围绕它绘制 SVG 路径并用于编写文本。结果:

代码:https://jsfiddle.net/ghLn4jkt/

<div class="mt-3 row">
    <div class="col-9 CircleThing" style="background-color: coral;">
        <img src="https://via.placeholder.com/500/" alt="contact" class="rounded-circle">
        <svg width="600" height="600">
            <!--Base circle for the text-->
            <!--<circle id="curve" cx="270" cy="270" r="260" stroke="black" stroke-width="3" fill="red" />--> 
            <path id="curve" fill="transparent"
                  d="M 10, 270        
                  a 260,260 0 1,0 520,0
                  a 260,260 0 1,0 -520,0 " />
            <text width="520">
                <textPath xlink:href="#curve"  >
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                </textPath>
            </text>
        </svg>
    </div>
</div>

CSS:

 .CircleThing {
  font-family: Gill Sans Extrabold;
  font-size: 50px;
}

问题:

在我最后一次尝试中,我遇到了多个问题:
1/。 svg 不在 img 之上。
2/。文本从左下角开始,而我希望它在右边。 为了创建路径,我首先做了一个 SVG 圆圈,在阅读 https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d 后推断它的路径是:

M cx, cy
a r,r 0 1,0 (r * 2),0
a r,r 0 1,0 -(r * 2),0

3/.文字颠倒或由内向外。对于右上角的四分之一

【问题讨论】:

  • 尝试将svg设置为绝对左侧:0

标签: html css twitter-bootstrap svg


【解决方案1】:

这是我的解决方案。请注意,我将#curve 颠倒为textPath。我还移动了 SVG 内的图像并用clipPath 进行了四舍五入。如果您需要使其具有响应性,这一点很重要。

svg{width:90vh;}
<div class="mt-3 row">
  <div class="col-9 CircleThing" style="background-color: coral;">
    <svg viewBox="-30 -30 600 600" style="background-color: black;">
<defs>
<path id="curve" d="M 10, 270 a 260,260 0 1,1 520,0 a 260,260 0 1,1 -520,0 " />
<clipPath id="clip">
<path d="M 40, 270a 230,230 0 1,0 460,0a 230,230 0 1,0 -460,0 " />
</clipPath>
</defs>
				 
<image xlink:href="https://via.placeholder.com/500/" clip-path="url(#clip)"/>
          
<text fill="white" font-size="40">
<textPath xlink:href="#curve" >
    some words
</textPath>
</text>
</svg>
  </div>
</div>

【讨论】:

  • 嘿,我不知道 SVG 中的图像。这是一个好主意,因为我可以轻松处理它们,因为它们与文本具有相同的中心。 This picture 真正总结了 large-arc-flagsweep-flag 上我在文档中错过的部分。从这个blender question。一旦我停止阅读 html 规范并开始阅读有关 svg 的 Illustrator 和 Blender 解释,一切都变得更加清晰了。
  • Ps:Img 未在 IE/Edge 上加载。没有大碍。但我不得不写它,因为它只是一个后方块,可能会让 IE/Edge 上的人感到困惑。
猜你喜欢
  • 2023-03-18
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
  • 1970-01-01
相关资源
最近更新 更多