Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text flowing out of div

Tags:

css

border

People also ask

Why does text go outside of Div?

This problem basically occurs when the height and width of DIV element are small such that all the text can not be fitted in that DIv. Here, the area of DIV element is shown by the red border, and we can clearly see that text is going beyond it. We can solve this problem by using CSS overflow property.

Why is my content overflowing div?

Overflow happens when there is too much content to fit in a box. CSS provides various tools to manage overflow. As you go further with CSS layout and writing CSS, you will encounter more overflow situations.

How do I get the contents to stay inside a div?

You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.


It's due to the fact that you have one long word without spaces. You can use the word-wrap property to cause the text to break:

#w74 { word-wrap: break-word; }

It has fairly good browser support, too. See documentation about it here.


Use

white-space: pre-line;

It will prevent text from flowing out of the div. It will break the text as it reaches the end of the div.


You should use overflow:hidden; or scroll

http://jsfiddle.net/UJ6zG/1/

or with php you could short the long words...


You need to apply the following CSS property to the container block (div):

overflow-wrap: break-word;

According to the specifications (source CSS | MDN):

The overflow-wrap CSS property specifies whether or not the browser should insert line breaks within words to prevent text from overflowing its content box.

With the value set to break-word

To prevent overflow, normally unbreakable words may be broken at arbitrary points if there are no otherwise acceptable break points in the line.

Worth mentioning...

The property was originally a nonstandard and unprefixed Microsoft extension called word-wrap, and was implemented by most browsers with the same name. It has since been renamed to overflow-wrap, with word-wrap being an alias.


If you care about legacy browsers support it's worth specifying both:

word-wrap    : break-word;
overflow-wrap: break-word;

Ex. IE9 does not recognize overflow-wrap but works fine with word-wrap


use overflow:auto it will give a scroller to your text within the div :).