Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollable div inside a table

I need to place a scrollable div in a table cell. The table should be 100% height. The div has a lot of content that doesn't fit in the screen so scrolling should appear. But I want only the div to be scrollable, not the whole page.
If I don't use table, everything is perfect:

<div style="height: 100%; width: 100px; padding: 5px; overflow: auto; border-width: 1px;  border-style: solid;">
    <div>
       Item 1<br/>
       Item 2<br/>
       ...
       Item 300<br/>
    </div>
</div>

Div is scrollable, page has no scrollbar. But if it's wrapped in a table:

<table style="height: 100%">
    <tr>
        <td>
            <div style="height: 100%; width: 100px; padding: 5px; overflow: auto; border-width: 1px;
                border-style: solid;">
                <div>
                   Item 1<br/>
                   Item 2<br/>
                   ...
                   Item 300<br/>
                </div>
            </div>
        </td>
    </tr>
</table>  

page becomes scrollable, and the div ceases to be such. What can I do?

like image 454
timkishkin Avatar asked Aug 02 '26 15:08

timkishkin


1 Answers

Shouldn't be height: 100%; and overflow: auto; on <td> ?

like image 141
MatTheCat Avatar answered Aug 05 '26 09:08

MatTheCat