1
4

1 回答 1

1

Are you using a fixed-width font? If so, you could count how many characters fit on one line, and if a given line is longer than that, step back through the characters until you hit a space, and split it there.

Even with a flexible layout, you could calculate how many characters can currently fit: Create a hidden <div> with the same font, and add characters to it until its height increases.

于 2012-10-14T16:28:17.710 回答