tags:

views:

30

answers:

2

Hi,

For some reason I think I'm forgetting something here. Below is my code:

<style type="text/css">
#content {
    width: 400px;
    height: 100px;
    background: orange;
    padding: 10px;
}
</style>
<div id="content">
<h1>what</h1>
foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
</div>

When that loads, it shows this: http://grab.by/6Mhp

The text is not inside the box. Why...? And how to fix?

+2  A: 

Add the style

word-wrap:break-word;

on your #content

#content {
    width: 400px;
    height: 100px;
    background: orange;
    padding: 10px;
    word-wrap:break-word;
}
BrunoLM
Weird I have to write that now. I wrote a website last night that didn't have that style at all, and now I have to use it? It's so weird. :\
bobsoup
That because your text doesn't have spaces, causing the element to be long. So you have to force the `#content` to break these words. It's just like `notepad`, you can activate and deactivate `word-wrap`.
BrunoLM
Oh wow, I see now. Thanks!
bobsoup
A: 

I don't think CSS will automatically break words into pieces to fit into the div. You could use overflow:hidden to hide the overflow. The example you already use should work fine if you have words that don't exceed the size of the div.

You can also use word-wrap:break-word but, IIRC, that requires either IE or CSS3 (though that probably represents a lot of browsers out there).

timfreilly