javascript - 如何在多行中均匀地平衡文本?

标签 javascript html css

我想显示一小段可能换行到两三行的文本。它位于一个高度可视化的元素内,出于样式设计的目的,我希望线条的长度尽可能相等,最好是一根而不是两根。

取而代之的是:

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/

相关文章:

javascript - 使用 jquerymobile 滚动标题文本

javascript - 为什么我无法使用 jquery content() 来查找我的 dom?

html - 如何使响应式 AdSense 单元在浏览器调整大小时更改其大小

javascript - 在复杂度为 O(n) 的 Javascript 对象中查找 3 个最大值的键?

c# - 保留回发时在客户端设置的表格单元格背景颜色

javascript - 以 <audio> 作为源的网络音频循环

php - wordpress - functions.php - preg_replace - <div<-tags

jquery - parent 与最亲近的人

css - 超过 480 像素的图像未使用媒体查询调整大小

html - Jquery ui 选项卡错误