How to adjust the height of the div according to the text?

Asked

Viewed 4,248 times

7

I created a div with a defined width, but when I insert a very large word the text keeps coming out of the div, how to continue to word at the bottom line?

  • only and you do not set the height of the div or use the overflow hiden

2 answers

10


Use:

word-wrap: break-word;

in that div.

  • +1 works perfectly in Firefox and Chrome. Could anyone check IE compatibility? I made an example: http://jsfiddle.net/tBNyz/

  • 1

    It worked perfectly in ie7, ie8, ie9, and ie10 :) @utluiz

  • @Pauloroberto Thanks!

  • 1

    http://caniuse.com/#search=word-wrap. This site is very good for checking compatibility.

0

To solve this I always make use of the property float:.

For example:

.minhaDiv { float:left; width:200px; }

Every time your text gets close to the size of this div, she will "break" to the bass line.

  • It doesn’t work if you have a bigger word than div.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.