Fixed Headers and Horizontal Scrolling in bootstrap 4

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
    <script>
        window.onload = function () {
            var tableCont = document.querySelector('#table-sample')
            function scrollHandle(e) {
                var scrollTop = this.scrollTop;
                this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)';
            }
            tableCont.addEventListener('scroll', scrollHandle)
        }
    </script>
</head>

<body>

    <div class='table-responsive' style="max-height: 200px;overflow: auto;" id='table-sample'>
        <table class="table table-bordered table-hover">
            <thead class="thead-light">
                <tr>
                    <th>#</th>
                    <th>Header1</th>
                    <th>Header2</th>
                    <th>Header3</th>
                    <th>Header4</th>
                    <th>Header5</th>
                    <th>Header6</th>
                    <th>Header7</th>
                    <th>Header8</th>
                    <th>Header9</th>
                    <th>Header10</th>
                    <th>Header11</th>
                    <th>Header12</th>
                    <th>Header13</th>
                    <th>Header14</th>
                    <th>Header15</th>
                    <th>Header16</th>
                    <th>Header17</th>
                    <th>Header18</th>
                    <th>Header19</th>
                    <th>Header20</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <th scope="row">1</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">2</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">3</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">4</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">5</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">6</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">7</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">8</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">9</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
                <tr>
                    <th scope="row">10</th>
                    <td>body1</td>
                    <td>body2</td>
                    <td>body3</td>
                    <td>body4</td>
                    <td>body5</td>
                    <td>body6</td>
                    <td>body7</td>
                    <td>body8</td>
                    <td>body9</td>
                    <td>body10</td>
                    <td>body11</td>
                    <td>body12</td>
                    <td>body13</td>
                    <td>body14</td>
                    <td>body15</td>
                    <td>body16</td>
                    <td>body17</td>
                    <td>body18</td>
                    <td>body19</td>
                    <td>body20</td>
                </tr>
            </tbody>
        </table>
    </div>
</body>

</html>
标签: 技巧
⇠ Distributed TensorFlow Amazon正式发布Textract ⇢

GFW VPN

提供vpn服务,针对中国互联网用户,完全可以突破GFW的封锁. 经过了长期测试,运行非常的稳定.

Send Mail

注册账号