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.
<span>lgasdfjksdajgdsglkgsadfasdfadfasdfadsfasdfasddkgjk</span>
Any ideas?
You can use the CSS property word-wrap:break-word; that will break words if they are too long for your range width.
word-wrap:break-word;
span { display:block; width:150px; word-wrap:break-word; }
<span>VeryLongLongLongLongLongLongLongLongLongLongLongLongExample</span>
Like this
Demo
li span{ display:block; width:50px; word-break:break-all; }
Try to execute css:
span { display: block; word-wrap:break-word; width: 50px; white-space: normal }
By default, a span is an inline element ... so this is not the default behavior.
span
inline
You can span this way by adding display: block; into your CSS.
display: block;
span { display: block; width: 100px; }
try it
span { display: block; width: 150px; }
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")