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

I want to create a span with a fixed width that when I type any thing in the span like <span>lgasdfjksdajgdsglkgsadfasdfadfasdfadsfasdfasddkgjk</span> , a long string of non-spaced text, the word(s) break or wrap to next line.

Any ideas?


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

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;
}

尝试下面的CSS:

span {
    display: block;
    word-wrap:break-word;
    width: 50px;
    white-space: normal
}
链接地址: http://www.djcxy.com/p/88104.html

上一篇: 休息在这里不起作用?

下一篇: 如何在固定宽度范围内打包或打破长文本/单词?