Add characters to line break

Hi, I have a list (ul) and it has several "li" in it.

With Javascript (jQuery), as I detect when line breaks and some characters are added at the start.

So for example:

I have a very looooong text in 200px width li.

Result:

I have a very looooong text 
in 200px width li.

And I want to add "+" to the beginning of a new line => the result:

I have a very looooong text 
 + in 200px width li.

THX

+3
source share
4 answers

How about something in pure CSS? Demo - http://jsfiddle.net/FDD7n/

Work for me in Chrome 11. This may require some tweaking depending on your font size :)

+2
source

, : div, , li css. li padding-left 15px. div + , 1 .

var plusses = $('li').height() / $('li').css('line-height').slice(0,-2); //number of lines
var i = 1;
var sLines = '<br />';  // the first line doesn't need a + 
while(i < plusses) {
    sLines+='+<br />'; // every other line does
    i++;
}
$('#newdiv').html(sLines);

, , css'ing the bunch!

+1

, , , . HTML, "\n" "\n +". , , ( ) , , .

0

The only way I can think (assuming the browser will wrap the break in white space) wraps all the words in the gap, and then programmatically loop through the tracking element y pos. If there are significant changes to y pos, you probably wrapped ... So you add a “+” and keep repeating.

Keep in mind that adding a “+” is likely to affect where the rest of the line will also be wrapped, and may cause additional line breaks

0
source

All Articles