Mozilla Firefox solution
Add:
display: inline-block;
to the style of your td.
Webkit based browsers (Google Chrome, Safari, ...) solution
Add:
display: inline-block;
word-break: break-word;
to the style of your td.
Note:
Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to the standard.
Opera solution
Add:
display: inline-block;
word-break: break-word;
to the style of your td.
The previous paragraph applies to Opera in a similar way.
Answer from Stencil on Stack OverflowMozilla Firefox solution
Add:
display: inline-block;
to the style of your td.
Webkit based browsers (Google Chrome, Safari, ...) solution
Add:
display: inline-block;
word-break: break-word;
to the style of your td.
Note:
Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to the standard.
Opera solution
Add:
display: inline-block;
word-break: break-word;
to the style of your td.
The previous paragraph applies to Opera in a similar way.
Word-Break has nothing to do with inline-block.
Make sure you specify width and notice if there are any overriding attributes in parent nodes. Make sure there is not white-space: nowrap.
see this codepen
<html>
<head>
</head>
<body>
<style scoped>
.parent {
width: 100vw;
}
p {
border: 1px dashed black;
padding: 1em;
font-size: calc(0.6vw + 0.6em);
direction: ltr;
width: 30vw;
margin:auto;
text-align:justify;
word-break: break-word;
white-space: pre-line;
overflow-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
}
</style>
<div class="parent">
<p>
Note: Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to
the standard.
</p>
</div>
</body>
</html>
white-space: nowrap will prevent word-break from taking effect. Some templates apply white-space: nowrap which necessitates overriding this attribute with white-space: normal.
To properly break long-words it requires to combine several CSS properties, I would suggest defining and applying helper class like this:
.break-long-words {
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: break-word;
hyphens: auto;
}
Properties explained:
- overflow-wrap and word-wrap are aliases for same thing but some browsers support one and not the other so we need them both. They are offical "correct" way to break words but they don't have any effect on elements with dynamic width so we need more...
- word-break is originally intended for requiring a particular behaviour with CJK (Chinese, Japanese, and Korean) text but works similar to word-wrap but in WebKit break-all value breaks everything and everywhere. For that reason we must use non-standard and poorly documented WebKit-only break-word value.
- and optionally, if it makes sense for break words to have hypens (ie. for URLs it probably doesn't) we can use hypens in browsers that support them (at the moment Firefox, Safari, Edge and IE 10+). Also note that in Firefox hypens don't work if you have word-brake property so unless you have fixed-width container you must choose between hypens on FF or legacy support.
Note that I omitted vendor prefixes but if you don't use something like Autoprefixer than this is full verison:
.break-long-words {
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
If you set it to display: inline-block and give it a max-width, it will break the word for you. You'll also need to remove the white-space: nowrap on the code element in your CSS, or disable it for your specific code.link class, by adding white-space: normal.
John suggestion not work at all, in order to work you must use also the properties entitled in this post:
So use below sample code:
<code style="display: inline-block;white-space: normal;max-width:100%; word-break:break-all; word-wrap:break-word;">anyyyyyyyylonnnnnngggggggggstringggggggggwillllbetrunnncateeeeeddddddd</code>
You can set any max-width, in integer PX, EM or by percentage nor just simply do not set a max-width, as it is not mandatory
You could also use, word-wrap: break-word;
.wrapper .right{
display: block;
width:200px;
}
.wrapper .right{
word-wrap:break-word;
}
.right should not be inline. Also, assign some width to it.
.wrapper .right{
display: block;
width: 200px;
}
.wrapper .right{
word-break: break-all;
}
DEMO here.
If word-wrap: break-all don't work, try also add this:
white-space:normal;
work for me with the .btn class in Bootstrap 3
Use word-break: break-all;
#fos { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size:14px;
font-weight: normal;
line-height: 18px;
width: 238px;
height:38px;
cursor: pointer;
word-break: break-all;
border:2px solid; }
LIVE DEMO
Here is another version of using table:
<div class="break-word-container">
very_long_word_without_spaces
</div>
and here are the styles:
.break-word-container {
display: table;
table-layout: fixed;
width: 100%;
word-wrap: break-word;
}
Finally I did small change in my layout which given a standard result across all the browsers.
- Added a table inside my div (Here my table will have only one row & one column).
- Given the following styles to the table - "table-layout: fixed;width: 100%;word-wrap: break-word;"
Now user input will go into the table & it wraps the small words, breaks the long words if they are overflowing from the container.
<small> is an inline element by default, which won't take on any settings that refer to block elements, like width. So if you still want to keep it and have the width setting work, you have to convert it to a block or inline-block element by adding display: block or display: inline-block. I added background colors in the snippet below to make it more obvious.
<small style="width: 15px; word-wrap: break-word;display:block;background:green;">+{{$s->type }} {{$s->name}}</small>
<small style="width: 15px; word-wrap: break-word;display:inline-block;background:yellow;">asfasfassaasfdffgdfgd</small>
Added after comments:
I suppose you have a situation like this:
.container {
width: 90px;
border: 1px solid #ccc;
}
.container small {
word-wrap: break-word;
}
<div class="container">
<p>This is a text that contains some <small>veeeeeeeeeeeerrrrrry</small> long words. This is a text that contains some <small>veeeeeeeeeeeerrrrrry</small> long words. This is a text that contains some <small>veeeeeeeeeeeerrrrrry</small> long words.</p>
</div>
Here the width applies to the container, not to small, small is only around the long words and contains the word-break property, so it's the only place where words can break:
You just need to add the property "display:inline-block", see the snippet:
<small style="width: 15px; word-wrap: break-word; display:inline-block">+{{$s->type }} {{$s->name}}</small>
<small style="width: 15px; word-wrap: break-word; display:inline-block">asfasfassaasfdffgdfgd</small>
It seems to work fine:
.txt {
word-break: break-all;
word-wrap: break-word;
min-height:150px;
max-width:150px;
overflow-x: auto;
}
<div class="txt">
The company's revenue has been increasing for the last five years with an overall growth of 49% between 2015 and 2019. Revenue increased 7% to $426.4 million for the year ended December 29, 2019, as compared to $398.2 million for the year ended December 30, 2018. The increase was primarily driven by $28.5 million in incremental revenue from an additional 359 operating weeks provided by new restaurants opened during and subsequent to the year ended December 30, 2018 as well as an increase in its comparable restaurant sales. Net income increased by $0.7 million and 12% to $6.2 million for the year ended December 29, 2019 as compared to $5.5 million during the comparable period in 2018. This was due to the increase in depreciation and amortization costs, as well as the increase in income tax benefits. The company's cash equivalents at the end of 2019 totaled $10.1 million, an increase of $2 million from the previous year. Operating activities generated $43.4 million, while investing activities used $33.3 million. Financing activities used another $8.3 million primarily for common stock repurchases and line of credit payments.
</div>
Did you "inspect" your div to see if some other css rule is messing the thing?

When you hit F12 in your browser and then select your div either by clicking on it (1 or 2), you'll see what styles are applied to it in 3.
You'll likely see word-break: break-all; or the same with word-wrap because it is overriden by some other rule.
you can do this instead of nesting div into td
.txt {
word-break: break-all;
word-wrap: break-word;
min-height:150px;
max-width:150px;
}
<table>
<tr>
<td class="txt">skdjfhskadjfhsdlkajfhdsakljfhsdakjfhslkadjfhsdalkjfhsadlkjfhsdalkjfhsadlkjfhsdakljfhsdalkjfhsadlkjfhsdalkjfhsladkjfhslakjfhlskadjfh</td>
<tr>
</table>
Use word-wrap:break-word;
It even works in IE6, which is a pleasant surprise.
word-wrap: break-word has been replaced with overflow-wrap: break-word; which works in every modern browser. IE, being a dead browser, will forever rely on the deprecated and non-standard word-wrap instead.
Existing uses of word-wrap today still work as it is an alias for overflow-wrap per the specification.
I am not sure about the browser compatibility
word-break: break-all;
Also you can use the <wbr> tag
<wbr>(word break) means: "The browser may insert a line break here, if it wishes." It the browser does not think a line break necessary nothing happens.