9

This is about basic HTML+CSS page rendering.

When a paragraph is too long to fit in one line, it occupies as much space as it can, then wraps, and again and so on.

I would like the line wrapping of my webpage to happen so that the resulting lines are as equal as possible.

So instead of getting:

wrap wrap wrap wrap wrap

wrap wrap wrap wrap wrap

wrap wrap wrap wrap wrap

wrap

with a very short last line, I would get:

wrap wrap wrap wrap

wrap wrap wrap wrap

wrap wrap wrap wrap

wrap wrap wrap wrap

with more balanced lines. This would be useful, for instance, for right-justified quotations that may or may not be wrapped, but look ugly when wrapped by just a little.

So I'm looking for a HTML/CSS command that tells the browsers to do this.

Remark: I'm not looking for the text to be justified. What I need is the lines to be wrapped in a way that they have roughly equal size rather than the last one being much shorter.

Is it possible?

user334639
  • 556
  • 5
  • 10
  • 1
    Where do you want to do this? At a command prompt? To an existing file? To text your output from a program? If the last, what language (C#, Java, Php...) & platform are you on (WinXP, Win7, Unix, Linix, MacOS...). Thanks. – Binary Worrier Aug 09 '11 at 13:10
  • Sorry. It's just HTML. I have edited the question to specify this. – user334639 Aug 09 '11 at 13:29
  • 1
    This would be cool but I suspect that javascript would be required. Possibly a routine that increases the padding of the containing element by 10px at a time until the height increases at which point it picks the previous width. It would have to reevaluate after each page resize. Interestingly I have the same need, to make quotations appear more balanced. – AnthonyVO May 10 '19 at 14:54
  • @AnthonyVO nice idea! Would you please post your solution here if you implement it? – user334639 May 12 '19 at 01:24
  • This is a really good question! I have this issue, for an in-page header, which is sometimes wide enough that words wrap on to the next line, and it would look much better if it was balanced, rather than just one word on the 2nd line. It really should be a CSS option. – JoLoCo Jul 11 '20 at 14:03
  • Also, this question was asked (with some reasonable answers) here: https://stackoverflow.com/questions/2908697/balanced-text-wrapping-in-html – JoLoCo Jul 11 '20 at 14:05

2 Answers2

0

You might try fmt or par:

fmt -w 80 input.txt

or

par 80jl < input.txt

Another option would be to use the justify.vim Vim script.

splicer
  • 5,344
  • 4
  • 42
  • 47
0

Try out the following css statement: text-align:justify;

or see the different options in action here.

Jonas
  • 342
  • 2
  • 13
  • Thanks, but... I'm not looking for the text to be justified. What I need is the lines to be wrapped in a way that they have roughly equal size rather than the last one being much shorter. – user334639 Aug 09 '11 at 18:24