Apparently a classic problem, but the “solutions” I’ve found haven’t worked, including various other questions on SO.
If my table is wider than its container, I want my table cell width to remain fixed and not be resized to fit the container.
Reproducible HTML (<td>s generated with PHP):
<html>
<head></head>
<body>
<table>
<tr>
<?php for($i=0;$i<15;$i++) {
echo "<td style='width:150px;border-right:1px solid black;'>".($i+1)."</td>";
} ?>
</tr>
</table>
<div style='background:chartreuse;width:150px'>This is 150px wide.</div>
</body>
</html>
What I’ve tried:
table-layout:fixedspancontainer withdisplay:inline-blocksetdivcontainer with inline block
It seems there should be an easy way to make the previous code generate a table that overflows the body.
Can someone help?
Edit
It may not be clear from my previous wording, but I want to specify column width myself.
I’m trying to do this without specifying an explicit width for the table. Only the TDs will force the table wider, which (should?) force the container wider.
Also, the inline CSS is there for example purposes only.
1 Answer