Reputation: 7547
I have this codepen here, shouldn't the text goes to new line when it reaches the right border of div?
html:
<div class="test">
<p>dfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodjdfsjiodj</p>
</div>
css:
div.test{
width:400px;
height:800px;
border-style: solid;
border-color: red;
margin:1px; padding:1px;
}
Upvotes: 3
Views: 47922
Reputation: 103
Because the text doesn't have any space, so it won't create a new line.
Try to put:
[space]/( )/( )
For example, I changed my text from:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
into:
xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx
It will create its own new line.
Upvotes: 0
Reputation: 389
You can do width:auto;
, but if you want specific width:400px;
you can use word-wrap:break-word
or word-wrap:break-all;
Upvotes: 0
Reputation: 446
I had this same issue, word break didn't look too pretty for me - so I found applying the below CSS to the container worked:
text-overflow: ellipsis;
overflow: hidden;
ellipsis has good browser support too, read more about ellipsis here
Upvotes: 1
Reputation: 8111
in my case it turned out to be this:
something something
counts as a single long word and hence went outside the div
Fixed it by doing
something something
Upvotes: 0
Reputation: 4055
Live Example http://codepen.io/elad2412/pen/LAhJw
div.test {word-break:break-all;}
Upvotes: 2
Reputation: 1555
Use word-wrap:break-word
div.test{
width:400px;
height:800px;
border-style: solid;
border-color: red;
margin:1px; padding:1px;
word-wrap:break-word;
}
Upvotes: 11