<style>
        tr th {
            background-color:red;
            position: sticky;
            top:0; (距离顶部的距离)(这个距离必须要指定,不然表头不会固定)
        }
</style>

  

 <table class="table">
        <thead style="background-color:red;">
            <tr>
                <th class="header">Course</th>
                <th class="header">Start Date</th>
                <th class="header">Fees</th>
                <th class="header">Type</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>CAT</td>
                <td>1st Aug</td>
                <td>Free</td>
                <td>Online</td>
            </tr>
            <tr>
                <td>GATE</td>
                <td>5th July</td>
                <td>Free</td>
                <td>Online</td>
            </tr>
        </tbody>
</table>

  效果: