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?
HTML. Small table: To make the table smaller in size use the class table-sm along with the class table within the <table> tag. This reduces the cell padding to half. To make the dark table smaller in size use the combination of classes table, table-sm, and table-dark within the <table> tag.
Add . w-auto class to the table element to set an auto width to the table column. The width of the columns will automatically adjust to the content of the column. That means it will always take a minimum width required to present its content.
.table-striped. Adds zebra-striping to any table row within <tbody> (not available in IE8) Try it. .table-bordered. Adds border on all sides of the table and cells.
Small table. Add . table-sm to make tables more compact by cutting cell padding in half.
.the-table { table-layout: fixed; word-wrap: break-word; }
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.
This works without forcing table layout to be fixed Just add it to td or any
.is-breakable { word-break: break-word; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With