Given a <table>
with one or many <td>
's with text that is wider than the parent <div>
, is there a way to make the table scroll without making the parent <div>
use overflow:auto
, and still have the table retain 100% width?
I'm hoping for a CSS solution I can apply to ONLY the <table>
element (or its children).
Example: See JSFiddle Demo.
CSS:
<style>
#wrapper {
width: 250px;
/* looking for solution that doesn't use overflow auto here */
}
table {
border-collapse: collapse;
}
td {
border:1px solid #ccc;
padding: 3px;
}
</style>
HTML:
<div id="wrapper">
<p>Table should scroll, but not this text.</p>
<table>
<thead>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</thead>
<tbody>
<tr>
<td>..</td>
<td>..</td>
<td>....................................................................................</td>
</tr>
<tr>
<td>..</td>
<td>..</td>
<td>..</td>
</tr>
</tbody>
</table>
</div>
Not modifying the parent div
is important in my project because <table>
's are in a <div>
with a bunch of other content that I do not want to scroll with it. While I could add a wrapper <div>
to all tables in my project, I would also have to rewrite a JavaScript plugin (has to do with paging), which I am trying to avoid.