I\'m trying to stop a table that has width explicitly declared from overflowing outside of its parent div. I presume I can do this in some way using max-w
You may try this CSS. I have experienced it working always.
div {
border-style: solid;
padding: 5px;
}
table {
width: 100%;
word-break: break-all;
border-style: solid;
}
<div style="width:200px;">
<table>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Col 5</th>
</tr>
<tr>
<td>data 1</td>
<td>data 2</td>
<td>data 3</td>
<td>data 4</td>
<td>data 5</td>
</tr>
<table>
</div>
I tried all the solutions mentioned above, then did not work. I have 3 tables one below the other. The last one over flowed. I fixed it using:
/* Grid Definition */
table {
word-break: break-word;
}
For IE11 in edge mode, you need to set this to word-break:break-all
A crude work around is to set display: table on the containing div.
overflow-x: auto;
overflow-y : hidden;
Apply the styling above to the parent div.
You can prevent tables from expanding beyond their parent div by using table-layout:fixed.
The CSS below will make your tables expand to the width of the div surrounding it.
table
{
table-layout:fixed;
width:100%;
}
I found this trick here.
There's a width="400" on the table, remove it and it will work...