在HTML中使文本字符串达到一定长度的最简单方法



这似乎是一个简单的问题,但我还没有找到简单的答案。我有一个特定的元素,它将出现在几行中,前面将是具有不同字符数的文本字符串。

因此,未优化的代码将如下所示:

<p>String of a certain length <example></example></p>
<p>String of a different length <example></example></p>
<p>Third string <example></example></p>

问题是我希望示例元素彼此垂直对齐。所以前面的字符串应该占用相同的空间。

我该怎么做?

如果它在HTML中过于复杂,那么将字符串设置为固定数量的字符也就足够了。我知道它们的长度可能不一样。

如果只能使用纯HTML,最简单的解决方案可能是只使用一个表。

<table>
<tr>
<td>String of a certain length</td>
<td>[element]</td>
</tr>
<tr>
<td>String of a different length</td>
<td>[element]</td>
</tr>
<tr>
<td>Third string</td>
<td>[element]</td>
</tr>
</table>

最新更新