I want a scrollable table. To achieve that, I wrap a <table>
into a <div>
with a max-height
and overflow: auto
. In addition, the <div>
has display: inline-block
to ensure that the div adjusts its width to the underlying table.
<html>
<head>
<title>Test</title>
<style type="text/css">
div { max-height: 100px; display: inline-block;
overflow: auto; border: 1px solid red; }
td { border-bottom: 1px solid black; }
</style>
</head>
<body>
<div>
<table>
<tr><td>bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla</td></tr>
</table>
</div>
</body>
</html>
In most browsers (Firefox, Safari, Chrome), this causes a problem: If the table is longer than 100px, vertical scroll bars are added without making the div wider, causing the text to wrap:
In IE it looks "correct":
Is there a way to fix this?