Balanced text wrapping in HTML

回眸只為那壹抹淺笑 提交于 2019-12-18 05:44:03

问题


In HTML, is there a way to evenly distribute text that is broken across multiple lines?

E.g., I don't want:

   Here is some really long label that ends up on
   two lines.

I'd prefer:

                  Here is some really long label 
                      that ends up on two lines.

回答1:


Adobe has proposed that a new css property be added text-wrap: balance.

In the meantime they have created a jQuery plugin named balance-text to achieve the same result.




回答2:


Somewhat of a workaround, but you can use non-breaking spaces for the last few words:

<p>Here is some really long label that ends on&nbsp;two&nbsp;lines</p>



回答3:


In pure HTML/CSS there isn't a way to accomplish this, because there is no way to measure the length of the line.

One way to do this would be with javascript, but you will end up with a FOBUC while the javascript calculates the line length and splits it accordingly.

The best way to avoid that would be to split the line with PHP/ASP/Whatever you're using.




回答4:


I think you can achieve that if you set fixed width of the element-container and play with padding properties.



来源:https://stackoverflow.com/questions/2908697/balanced-text-wrapping-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!