Hiding does not work

I am trying to make tbody overflow hidden for y and auto for x, but without success, I tried several methods here,

http://jsfiddle.net/wxdgf4pr/2

http://jsfiddle.net/wxdgf4pr

http://jsfiddle.net/wxdgf4pr/1

but no one worked, I want yours to scroll in such a way that it stays where it is.

HTML

<div id="fruitcratebody" style="height: 300px; width: 500px; background:red;">
    <div id="fruitcrateContainer">
        <table id="fruitcrateTable" class="tablesorter" style="display: table;">
            <thead>
                <tr>
                    <th class="header">Column1</th>
                    <th class="header">Column2</th>
                    <th class="header">Column3</th>
                    <th class="header">Column4</th>
                    <th class="header">Column5</th>
                    <th class="header">Column6</th>
                    <th class="header">Column7</th>
                </tr>
            </thead>
            <tbody id="fruitcrateTBody">
                <tr>
                    <td>0</td>
                    <td>Calculate1</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

CSS

tbody{
    position:relative;
    overflow:hidden;
    height:300px;
}

I need something like this, but now I have problems aligning the width of the columns,

enter image description here

+4
source share
5 answers

, , , , , , . .

, , .

, - . , , table-display: fixed.

( ) div .

. , , jQuery, , , http://www.fixedheadertable.com

, table-sort .

jQuery, , :

http://mottie.imtqy.com/tablesorter/docs/index.html

.

.fruitcrateTable {
    border: 1px dotted blue;
    width: 520px;
}
.fruitcrateTable table {
    width: 500px;
    table-layout: fixed;
}
.fruitcrateTable table th, .fruitcrateTable table td {
    width: 15%;
    border: 1px dotted gray;
}
.fruitcrateTable .table-body-scroll {
    height: 300px;
    overflow-y: auto;    /* Trigger vertical scroll    */
    overflow-x: hidden;  /* Hide the horizontal scroll */
}
<div class="fruitcrateTable">
<table class="header-table">
    <thead>
        <tr>
            <th class="header">Column1</th>
            <th class="header">Column2</th>
            <th class="header">Column3</th>
            <th class="header">Column4</th>
            <th class="header">Column5</th>
            <th class="header">Column6</th>
            <th class="header">Column7</th>
        </tr>
    </thead>
</table>
<div class="table-body-scroll">
        <table>
            <tbody>
                <tr>
                    <td>0</td>
                    <td>Calculate1</td>
                    <td>Calculate1</td>
                    <td>Calculate1</td>
                    <td>Calculate1</td>
                    <td>Calculate1</td>
                    <td>Calculate1</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>Calculate2</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
Hide result
+3

#fruitcrateContainer {
    height: 100px;
    overflow-y: scroll;
    background:red;
}

: http://jsfiddle.net/wxdgf4pr/12/

+1

over-flow fixed height div,

, JS FIDDLE

0

- , CSS,

thead, tbody { display: block; }

tbody {
    height: 100px;       /* Just for the demo          */
    overflow-y: auto;    /* Trigger vertical scroll    */
    overflow-x: hidden;  /* Hide the horizontal scroll */
}

http://jsfiddle.net/wxdgf4pr/8/

0

CSS

tbody{
    position:relative;
    overflow:hidden;
    height:300px;
}

thead > tr, tbody{
    display:block;
}

DEMO

0

Source: https://habr.com/ru/post/1583997/


All Articles