How to stick table header(thead) on top while scrolling down the table rows with fixed header(navbar) in bootstrap 3?

后端 未结 10 2124
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 03:04

Bootstrap layout with fixed-navbar. Having table with so many rows in body.

Issue? As i scroll the page navigation-bar will be there be

10条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 03:45

    You can do it easily with puse CSS without any kind of JS. you have to add position: sticky; top: 0; z-index:999; in table th . But this won't work on Chrome Browser but other browser. To work on chrome you have to add those code in table thead th

    .table-fixed {
      width: 100%;
    }
    
    /*This will work on every browser but Chrome Browser*/
    .table-fixed thead {
      position: sticky;
      position: -webkit-sticky;
      top: 0;
      z-index: 999;
      background-color: #000;
      color: #fff;
    }
    
    /*This will work on every browser*/
    .table-fixed thead th {
        position: sticky;
        position: -webkit-sticky;
        top: 0;
        z-index: 999;
        background-color: #000;
        color: #fff;
    }
    Table Header 1 Table Header 2 Table Header 3
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data
    Data Data Data

提交回复
热议问题