100% width table overflowing div container
From a purely "make it fit in the div" perspective, add the following to your table class (jsfiddle):
table-layout: fixed;
width: 100%;
Set your column widths as desired; otherwise, the fixed layout algorithm will distribute the table width evenly across your columns.
For quick reference, here are the table layout algorithms, emphasis mine:
- Fixed (source)
With this (fast) algorithm, the horizontal layout of the table does not depend on the contents of the cells; it only depends on the table's width, the width of the columns, and borders or cell spacing.
- Automatic (source)
In this algorithm (which generally requires no more than two passes), the table's width is given by the width of its columns [, as determined by content] (and intervening borders).
[...] This algorithm may be inefficient since it requires the user agent to have access to all the content in the table before determining the final layout and may demand more than one pass.
Click through to the source documentation to see the specifics for each algorithm.
Try adding
word-break: break-all
to the CSS on your table element.
That will get the words in the table cells to break such that the table does not grow wider than its containing div, yet the table columns are still sized dynamically. jsfiddle demo.
Try adding to td
:
display: -webkit-box; // to make td as block
word-break: break-word; // to make content justify
overflowed tds will align with new row.
Add display: block;
and overflow: auto;
to .my-table
. This will simply cut off anything past the 280px
limit you enforced. There's no way to make it "look pretty" with that requirement due to words like pélagosthrough
which are wider than 280px
.