我想显示一小段可能换行到两三行的文本。它位于一个高度可视化的元素内,出于样式设计的目的,我希望线条的长度尽可能相等,最好是一根而不是两根。
取而代之的是:
This is an example of a piece of text that will wrap to two
lines.
我想要这个:
This is an example of a piece of
text that will wrap to two lines.
但是我不想限制文本容器的宽度:
This text is long enough to just barely fit in two lines. It
should not wrap to three or more lines so no width limiting.
有没有办法用纯 CSS 或使用可容忍数量的 JavaScript 来做到这一点?
最佳答案
CSS 文本模块 4 属性:
text-wrap: balance;
会这样做。 https://drafts.csswg.org/css-text-4/#text-wrap
还有 a package它为现有浏览器实现了一个 polyfill。
这是一个 demo of balance text 。 [ Archived copy ]
关于javascript - 如何在多行中均匀地平衡文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34875725/