Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table in div with scrollbar

Tags:

html

css

is it possible to put table in scrollable div? I tried, but then displaying bigger table with more rows and columns, distorts others divs, i mean shows in that scrollable div other divs from lower.

Thank you, Best Regards

like image 202
Prampam Avatar asked Jul 23 '13 11:07

Prampam


2 Answers

HTML

<div class="table-wrapper">
    <table>
        <tr>
            <td>A</td>
            <td>B</td>
            <td>C</td>
            <td>D</td>
        </tr>
        <tr>
            <td>A</td>
            <td>B</td>
            <td>C</td>
            <td>D</td>
        </tr>
        <tr>
            <td>A</td>
            <td>B</td>
            <td>C</td>
            <td>D</td>
        </tr>
        <tr>
            <td>A</td>
            <td>B</td>
            <td>C</td>
            <td>D</td>
        </tr>
    </table>      
</div>

CSS

.table-wrapper
{
    border: 1px solid red;
    width: 100px;
    height: 50px;
    overflow: auto;
}

table
{
    border: 1px solid black;
    margin-right: 20px;
}

td
{
    width: 20px;
    height: 20px;
    background-color: #ccc;
}

JSFiddle

http://jsfiddle.net/gvee/v54Sz/

like image 140
gvee Avatar answered Nov 11 '22 15:11

gvee


Set a style on your div with the width and height and set overflow to auto

like image 30
Mark Redman Avatar answered Nov 11 '22 14:11

Mark Redman