Search code examples
csstwitter-bootstraphtml-tabletableheader

bootstrap Table header fixed issue


I'm using bootstrap. I'm trying to use a fixed table header, but its not being fixed, it can be scrolled. I don't want to scroll a table header, I want to have a fixed table header. Please help me to fix it.

This is my code sample:

This is my code:

  <div class="widget-content">
          <div class="container">
            <table class="table table-bordered">
              <thead>
              <th class="text-center"> my</th>
              <th class="text-center"> text / line</th>
              <th  class="text-center">caps/ lock</th>
              <th  class="text-center">Value</th>
              <th  class="text-center">Qty</th>
              <th  class="text-center">other</th>
              </thead>
              <tbody>

                <tr class="dt-picked">
                  <td class="text-center">
                      <span style="color:white; font-weight:bold;"> text</span>

                  </td>
                  <td class="text-center">
                    <p>text</p>

                  </td>
                  <td class="text-center ">
                    <p>text</p>
                   <p>text</p>
                  </td>
                  <td class="text-center"> <p>text</p></td>
                  <td class="text-center b-color-1"><p>text</p></td>
                  <td>
                    class="btn btn-mini btn-danger" role="button">Sell</a>
                  </td>
                </tr>

              <tr>
                <td colspan="4" class="text-right no-stripe">Total Cash</td>
                <td class="b-color-1"><p>text</p></td>
              </tr>
              <tr>
                <td colspan="4" class="text-right no-stripe">Total Invested</td>
                <td class="b-color-1"><p>text</p></td>
                <td colspan="2" class="no-stripe"></td>
              </tr>
              <tr>
                <td colspan="4" class="text-right bold no-stripe">Bottom Line</td>
                <td class="b-color-1 bold"><p>text</p></td>
                <td colspan="2" class="no-stripe"></td>
              </tr>
              </tbody>
            </table>
          </div>
        </div> 

Solution

  • I got a fiddle for you

    <thead>
        <tr class="header">
          <th>
            Table attribute name
            <div>Table attribute name</div>
          </th>
          <th>
            Value
            <div>Value</div>
          </th>
          <th>
            Description
            <div>Description</div>
          </th>
        </tr>
      </thead>
    

    https://jsfiddle.net/byB9d/14995/