Reputation:
Lets say I have a fixed-width container with a long string inside, no spaces:
div {
background-color:yellow;
width:100px;
height:100px;
position:relative;
}
<div>veryveryveryveryveryveryveryveryveryveryveryverylongstring</div>
How do I force the text to wrap via CSS? And what control do I have over that wrapping style (using a hyphen or not for example)?
I'm aware of the text-wrap
property, but that doesn't seem to apply to a long string like this. Maybe I'm wrong. Could someone please explain this?
Upvotes: 5
Views: 5711
Reputation: 240978
You're looking for the word-break
property. You could use word-break: break-all
:
div {
background-color: yellow;
width: 100px;
height: 100px;
position: relative;
word-break: break-all;
}
<div>veryveryveryveryveryveryveryveryveryveryveryverylongstring</div>
Upvotes: 9