Responsive Bootstrap Table with Sticky Header

旧时模样 提交于 2020-07-22 06:08:10

问题


I have a table. The only CSS I am adding to the standard Bootstrap library is the following to implement the sticky header:

.table-sticky th {
  background: #fff;
  position: sticky;
  top: -1px;
  z-index: 990;
}
<div class="table-responsive p-0 mt-2">
  <table class="table table-sm table-striped table-hover table-sticky">
    <thead>
      <tr>
        <th>#</th>
        <th>Header</th>
        <th>Header</th>
        <th>Header</th>
        <th>Header</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1,001</td>
        <td>Lorem</td>
        <td>ipsum</td>
        <td>dolor</td>
        <td>sit</td>
      </tr>
      <tr>
        <td>1,002</td>
        <td>amet</td>
        <td>consectetur</td>
        <td>adipiscing</td>
        <td>elit</td>
      </tr>
    </tbody>
  </table>
</div>

The sticky header worked until I wrapped the table in the div.table-responsive. How do I allow these to co-exist?


回答1:


There's no way to co-exist a position: sticky inside a .table-responsive without re-implementing the latter.

My solution ended up to be using .table-responsive-sm to refuse this trade-off when a responsive table is certainly not needed.



来源:https://stackoverflow.com/questions/55483466/responsive-bootstrap-table-with-sticky-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!