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 Overflow
Top answer
1 of 11
135

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.

2 of 11
98

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>

🌐
CSS-Tricks
css-tricks.com › almanac › properties › o › overflow-wrap
overflow-wrap | CSS-Tricks
September 28, 2022 - The overflow-wrap property in CSS allows you to specify that the browser can break a line of text inside the targeted element onto multiple lines in an otherwise unbreakable place. This helps to avoid an unusually long string of text causing layout problems due to overflow. ... normal: the default. The browser will break lines according to normal line breaking rules. Words or unbroken strings will not break, even if they overflow the container.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › overflow-wrap
overflow-wrap - CSS | MDN
The same as the anywhere value, with normally unbreakable words allowed to be broken at arbitrary points if there are no otherwise acceptable break points in the line, but soft wrap opportunities introduced by the word break are NOT considered when calculating min-content intrinsic sizes.
🌐
Mozilla Bugzilla
bugzilla.mozilla.org › show_bug.cgi
1136818 - Word wrap break word doesn't work in flexbox, fieldset
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36 Steps to reproduce: Apply word-wrap: break-word to a div and then insert a frameset or display: flex div inside of that. Finally, insert a non-breaking string ...
Top answer
1 of 6
35

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.

2 of 6
22

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;
}
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Text › Wrapping_breaking_text
Wrapping and breaking text - CSS | MDN
<div class="box box1">A Very LongWordThatHasNoBreakingPossibilities</div> <div class="box box2">A Very LongWordThatHasNoBreakingPossibilities</div> ... .box { border: 4px solid #f76707; border-radius: 5px; padding: 10px; inline-size: 30ch; margin-block-end: 1em; } .box1 { word-break: break-all; } .box2 { overflow-wrap: break-word; } This might be useful if you want to prevent a large gap from appearing if there is just enough space for the string. Or, where there is another element that you would not want the break to happen immediately after.
Find elsewhere
🌐
CSS-Tricks
css-tricks.com › almanac › properties › w › word-break
word-break | CSS-Tricks
July 12, 2021 - This code works for me wonderfully. white-space: pre-wrap; /* css-3 / white-space: -moz-pre-wrap; / Mozilla, since 1999 / white-space: -pre-wrap; / Opera 4-6 / white-space: -o-pre-wrap; / Opera 7 / word-wrap: break-word; / Internet Explorer 5.5+ */ ... The “word-break : break-all” parameter is also useful for writing in Runic script, which allows line breaks within words.
Top answer
1 of 2
3

<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:

2 of 2
0

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>

🌐
Stack Overflow
stackoverflow.com › questions › 66358888 › text-doesnt-wrap-inside-div-and-word-break-is-not-working
html - Text doesnt wrap inside div and word-break is not working - Stack Overflow
.card { display: inline-block; width: auto; height: 75vh; margin-right: 20px; margin-top: 12.5vh; width: 20vw; background: red; } p { width: 10%; word-break: break-all; } <div class="card one"> <p> a lot of text</p> </div> ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Does the inscription on the stake provide clues about the reason why the Roman empire wanted Jesus dead even before all of the accusations against him
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › word-break
word-break - CSS | MDN
Has the same effect as word-break: normal except that language-specific analysis is performed to improve word breaks by not placing them in the middle of natural phrases. ... Has the same effect as overflow-wrap: anywhere combined with word-break: normal, regardless of the actual value of the overflow-wrap property.
Top answer
1 of 2
5

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.

2 of 2
2

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>

🌐
GitHub
github.com › dompdf › dompdf › issues › 2868
word-wrap: break-word not working any longer · Issue #2868 · dompdf/dompdf
March 31, 2022 - In version 0.8.6 the css property "word-wrap: break-word;" on table cells was working as expected (a word is split in a table column with a fixed width): In our tests with dompdf version 1.1.1 and 1.2.1 the property doesn't seem to have ...
Author   PDFCoder
🌐
GitHub
github.com › Kozea › WeasyPrint › issues › 541
"overflow-wrap: break-word" not working in table · Issue #541 · Kozea/WeasyPrint
October 14, 2017 - I'm implementing table inside html, but line break seems not working in items in table. This is CSS · table { ... td, th { padding: 5px 15px 5px 15px; word-break: break-all; white-space:nowrap; } ... ... <div class="item-box"> <table> ...
Author   kination
🌐
Coder's Block
codersblock.com › blog › deep-dive-into-text-wrapping-and-word-breaking
Deep Dive into Text Wrapping and Word Breaking / Coder's Block
This means that word-break: normal (the default) and word-break: break-all will give you the same results. However, you can use word-break: keep-all to prevent CJK text from wrapping within words (non-CJK text will be unaffected). Here’s an example in Korean. Note how the word “자랑스럽게” does or doesn’t break.