Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line break in a span with defined width?

How can I break a line in a span once the width of the span is reached? I tried max-width, but this did not work, the span is always as long as the text.

Ideas?

Thanks!

like image 938
user1638055 Avatar asked Oct 02 '12 13:10

user1638055


2 Answers

By default, <span> elements are 'inline', and will always grow to the size of their content. You need to explicitly declare the <span> to be display: block; or display: inline-block;.

like image 82
chipcullen Avatar answered Oct 02 '22 05:10

chipcullen


span { 
    display:block;
    width:150px;
    word-wrap:break-word;
}
like image 38
Qaisar Nadeem Avatar answered Oct 02 '22 06:10

Qaisar Nadeem