Make TBODY scrollable in Webkit browsers

后端 未结 14 1862
闹比i
闹比i 2020-11-29 20:33

I\'m aware of this question, but none of the answers work in Safari, Chrome, etc.

The accepted strategy (as demonstrated here) is to set the tbody height and overflo

相关标签:
14条回答
  • Add display:block; This will also remove the unnecessary horizontal scroll in FireFox as well. You are also, no doubt, aware that neither example works in MSIE 8.

    <table>
        <thead>
            <tr><th>This is the header and doesn't scroll</th></tr>
        </thead>
        <tbody style="height:100px; overflow:auto;display:block;">
            <tr><td>content that scrolls</td></tr>
            <tr><td>content that scrolls</td></tr>
            <tr><td>content that scrolls</td></tr>
            <tr><td>content that scrolls</td></tr>
            <tr><td>content that scrolls</td></tr>
            <tr><td>content that scrolls</td></tr>
            <tr><td>content that scrolls</td></tr>
        </tbody>
    </table>
    
    0 讨论(0)
  • 2020-11-29 21:02

    Using the display:block style only works if you have 1 column. If you have multiple data columns - with multiple fields - then display:block appears to make all data columns scrollable but under the 1st column (does the same in Firefox - which is the only browser I know that does tbody scrolling nicely). Incidentally, on Firefox - you can use the overflow-x: hidden style to suppress the horizontal scroll.

    I realized that the issue I mention only occurs if you are not specifying a width for the th & td elements - if you can fix the column widths then it works. Problem for me is I can't fix the column widths.

    0 讨论(0)
提交回复
热议问题