How can I wrap or break a long text / word in a fixed width range?

I want to create a fixed-width range, which when I enter something into the range, for example <span>lgasdfjksdajgdsglkgsadfasdfadfasdfadsfasdfasddkgjk</span> , a long line of text without markup, the word is broken or wrap to the next line.

Any ideas?

+52
html css
Aug 14 '13 at 7:07
source share
6 answers

You can use the CSS property word-wrap:break-word; that will break words if they are too long for your range width.

 span { display:block; width:150px; word-wrap:break-word; } 
 <span>VeryLongLongLongLongLongLongLongLongLongLongLongLongExample</span> 
+112
Aug 14 '13 at 7:10
source share

Like this

Demo

  li span{ display:block; width:50px; word-break:break-all; } 
+11
Aug 14 '13 at 7:09
source share

Try to execute css:

 span { display: block; word-wrap:break-word; width: 50px; white-space: normal } 
+4
Dec 17 '15 at 16:50
source share

By default, a span is an inline element ... so this is not the default behavior.

You can span this way by adding display: block; into your CSS.

 span { display: block; width: 100px; } 
+3
Aug 14 '13 at 7:10
source share

try it

 span { display: block; width: 150px; } 
0
Aug 14 '13 at 7:16
source share

I added to my code behind. Similar answer as above.

  Dim lblSite As Label lblSite.Text = "lgasdfjksdajgdsglkgsadfasdfadfasdfadsfasdfasddkgjk" lblSite.Attributes.Add("style", "display:inline-block;width:175px;word-wrap:break-word;white-space: normal") 
-3
Mar 08 '17 at 15:51
source share



All Articles