Click to See Complete Forum and Search --> : automatic word wrap so that lines are of equal length?


wouldbewebmaste
04-02-2007, 10:53 AM
Suppose you have a table cell. You have some text in the cell. Regardless of if its centered or right or left justified, if the text would be wider than the cell, it will wrap to a new line. The first line, and each line except the last line, will always take up as much width of the cell as possible.

Now I have some text in a cell that happens to take up two lines. What wraps to the second line is not enough to fill it up. This text, by the way, is centered. So I have a full-width line of text, and under that, the remainder takes up half a line. I'd like for the width of both lines of text to be the same. I'd like it to look balanced.

Now I don't want to adjust the width of the cell so that the text is forced to balance, because the text is dynamic. It changes. Also, my users use different resolutions. For people using narrower resolutions, the table might force horizontal scrollbars. For people with wider resolutions, they might be able to have the text all on one line. That won't happen if I force the width of the cell.

So I was hoping there was some kind of HTML tag or something that would make text balance out in width over multiple lines.

I hope that is a better explanation.

jogol
04-02-2007, 11:10 AM
maybe try css word-spacing and letter-spacing properties?

Taschen
04-02-2007, 11:16 AM
I'd like for the width of both lines of text to be the same. I'd like it to look balanced.

So I was hoping there was some kind of HTML tag or something that would make text balance out in width over multiple lines.

The technical term for what you are trying to achieve is text "Justification". This may be possible with CSS as there is an attribute called "text-align".

Try this:
<p style="text-align:justify;">Some text.</p>

wouldbewebmaste
04-02-2007, 12:23 PM
The technical term for what you are trying to achieve is text "Justification". This may be possible with CSS as there is an attribute called "text-align".

Try this:
<p style="text-align:justify;">Some text.</p>

sadly no-- justifcation is something different. justifying will keep the line break where it normally would be, but it will add spacings out so that the width is maximum. What I need is for the break to come earlier, so that there are roughly equal number of characters on each line.

So, say I have a table cell that has the text "1 2 3 4 5 6 7 8 9 0"

Normally, a browser will show a full first line and a nearly-empty second line:
1 2 3 4 5 6 7 8 9
0

What I want is a browser to first determine how many lines are going to be needed, but insert the line break so that an equal number of characters are on each line:

1 2 3 4 5
6 7 8 9 0

NogDog
04-02-2007, 12:33 PM
That would require some sort of programming to count characters and then decide where to split them. You could do it server-side with PHP, ASP, Perl, etc., or client-side with JavaScript.