Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit text width

Tags:

html

css

I would like to limit the width of a block of text so it will look like it has br at the ned of each line.

Something like this:

Texttttttttttttttttttttt tttttttttttttttttttttttt tttttttttttttttttttttttt 

From this:

Texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt

I have tried to specify the div's or p's width, but it didn't work for me. Any suggestions?

like image 661
Taboo Loco Avatar asked Mar 14 '13 12:03

Taboo Loco


People also ask

How do you restrict text size in HTML?

The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.

How do I limit text in span?

You can use the CSS property max-width and use it with ch unit. And, as this is a <span> , use a display: inline-block; (or block). Thanks , max-width: 13ch and display:inline-block allow me to concatenate text one by one with fixed size.

How do you change text width in HTML?

1. Set width in HTML. In HTML, you can use the width attribute to set the width of an element. Alternatively, you can also use the size attribute to define the width of the <input> .


2 Answers

 display: inline-block; max-width: 80%; height: 1.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;  
like image 35
Lekhraj Avatar answered Oct 04 '22 09:10

Lekhraj


You can apply css like this:

div {    word-wrap: break-word;    width: 100px; } 

Usually browser does not break words, but word-wrap: break-word; will force it to break words too.

Demo: http://jsfiddle.net/Mp7tc/

More info about word-wrap

like image 70
Viktor S. Avatar answered Oct 04 '22 09:10

Viktor S.