Bootstrap tables overflowing with long unspaced text

CssTwitter BootstrapCss Tables

Css Problem Overview


I'm using Bootstrap and I have a table with a few columns, the last of which sometimes has a long piece of text without spaces. I noticed that under certain screen sizes, the table would overflow its parent div and create ugly overlapping with its sibling table.

I played around with it and I think the problem has to do with the text being unspaced. I created a jsfiddle that demonstrates what I mean.

As you can see, the top leftmost table is well behaved and simply grows vertically to accommodate more text. However, the bottom left table leads to an overflow on the right due to the long unspaced text and the right column of the bottom left table winds up "under" its sibling.

Does anyone have any tips on how I can fix this so that the very long text gets clipped or partially split onto a new line?

Css Solutions


Solution 1 - Css

.the-table {
    table-layout: fixed;
    word-wrap: break-word;
}
Deprecated (i.e. word-wrap)

Add the following styles to your <table>

.the-table {
    table-layout: fixed;
    over-flow: break-word;
}

Then you can adjust your layout via-CSS as you wish.

Solution 2 - Css

This works without forcing table layout to be fixed Just add it to td or any

.is-breakable {
  word-break: break-word;
}

Solution 3 - Css

I was having trouble with these solutions working in Internet Explorer.

I used the following style to get it to finally work.

<td style="word-break: break-all">

Solution 4 - Css

You can use below css. This will wrap the text and apply ... in the end of the text.

e.g. This_is_a_large_text will be changed to This_is_a_lar...

td {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

You can also add tool tip to show the complete text value.

<td data-toggle="tooltip" title="${text}">${text}</td>

Solution 5 - Css

Albers answer did the trick for me

.the-table {
 table-layout: fixed;
 word-wrap: break-word;
}

In the JS to load it dynamically add

 $("#"  + tableName ).addClass('the-table'); 

Hope it helps!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRichard BenderView Question on Stackoverflow
Solution 1 - CssalbertedevigoView Answer on Stackoverflow
Solution 2 - CssKate KasinskayaView Answer on Stackoverflow
Solution 3 - CssJustin IpsonView Answer on Stackoverflow
Solution 4 - CssRahul GodaraView Answer on Stackoverflow
Solution 5 - CssSaurabh ValsangkarView Answer on Stackoverflow