简体   繁体   English

带有 svg 和 tspan 的 ul 列表

[英]ul list with svg and tspan

I'm trying to use text wrapping in a text/tspan svg element.我正在尝试在 text/tspan svg 元素中使用文本换行。 I'm essentially try to take the code such as this: (ignore the text wrapping part of it for right now)我基本上是尝试采用这样的代码:(现在忽略它的文本包装部分)

<svg>
    <g>
        <text>
             Date: date here
            <tspan>this is a list item</tspan>
            <tspan>this is another list item</tspan>
        </text>
    </g>
</svg>

I'm trying to make it like an unordered HTML list:我试图使它像一个无序列表的 HTML 列表:

Date: date here
<ul>
    <li>this is a list item</li>
    <li>this is another list item</li>
</ul>

is there a way to do this?有没有办法做到这一点?

In SVG, you need to manually position each line of text.在 SVG 中,您需要手动定位每一行文本。

You could layout the text using a separate <text> element for each line.您可以为每行使用单独的<text>元素来布局文本。 For example...例如...

<svg>
    <g>
        <text x="0em" y="1em">Date: date here</text>
        <circle cx="1.75em" cy="2.75em" r="2px"/>
        <text x="2.5em" y="3em">this is a list item</text>
        <circle cx="1.75em" cy="3.75em" r="2px"/>
        <text x="2.5em" y="4em">this is another list item</text>
    </g>
</svg>

Or you could layout the text using a single <text> with a separate <tspan> element for each line break.或者您可以使用单个<text>布局文本,每个换行符都有一个单独的<tspan>元素。 For example...例如...

<svg>
    <g>
        <circle cx="1.75em" cy="2.75em" r="2px"/>
        <circle cx="1.75em" cy="3.75em" r="2px"/>
        <text x="0em" y="1em">
            Date: date here
            <tspan x="2.5em" dy="2em">this is a list item</tspan>
            <tspan x="2.5em" dy="1em">this is another list item</tspan>
        </text>
    </g>
</svg>

Edit: Added <circle> elements for the dots before each list item.编辑:为每个列表项之前的点添加<circle>元素。

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

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