【问题标题】:How to fix left column table in bootstrap 3.3.7 [duplicate]如何在引导程序 3.3.7 中修复左列表 [重复]
【发布时间】:2018-04-04 13:37:05
【问题描述】:

我需要在 bootstrap 3.3.7 中修复左表列(日期和所有列名)。

我尝试使用 position: fixed;符合,但效果不好。

我该怎么办。

https://fiddle.jshell.net/umj9zknj/

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<table class="table table-hover table-striped table-bordered">
  <tr>
    <td colspan="15"> Thu 05 th Apr, 2018</td>
  </tr>
  <tr>
    <td> Name </td>
    <td> 08.00-08.30 </td>
    <td> 08.30-09.00 </td>
    <td> 09.00-09.30 </td>
    <td> 09.30-10.00 </td>
    <td> 10.00-10.30 </td>
    <td> 10.30-11.00 </td>
    <td> 11.00-11.30 </td>
    <td> 11.30-12.00 </td>
    <td> 12.00-12.30 </td>
    <td> 12.30-13.00 </td>
    <td> 13.00-13.30 </td>
    <td> 13.30-14.00 </td>
    <td> 14.00-14.30 </td>
    <td> 14.30-15.00 </td>
  </tr>
  <tr>
    <td> Jack </td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

【问题讨论】:

    标签: jquery html css twitter-bootstrap


    【解决方案1】:

    试试这个。

    table {
      border-collapse: separate;
      border-spacing: 0;
      border-top: 1px solid grey;
    }
    
    td, th {
      margin: 0;
      border: 1px solid grey;
      white-space: nowrap;
      border-top-width: 0px;
    }
    
    div {
      width: 500px;
      overflow-x: scroll;
      margin-left: 5em;
      overflow-y: visible;
      padding: 0;
    }
    
    .headcol {
      position: absolute;
      width: 5em;
      left: 0;
      top: auto;
      border-top-width: 1px;
      /*only relevant for first row*/
      margin-top: -1px;
      /*compensate for top border*/
    }
    
    
    .long {
      height:35px;
      letter-spacing: 1em;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <div>
    <table class="table table-hover table-striped table-bordered">
      <tr>
        <td colspan="15"> Thu 05 th Apr, 2018</td>
      </tr>
      <tr>
        <th class="headcol"> Name </th>
        <td class="long"> 08.00-08.30 </td>
        <td class="long"> 08.30-09.00 </td>
        <td class="long"> 09.00-09.30 </td>
        <td class="long"> 09.30-10.00 </td>
        <td class="long"> 10.00-10.30 </td>
        <td class="long"> 10.30-11.00 </td>
        <td class="long"> 11.00-11.30 </td>
        <td class="long"> 11.30-12.00 </td>
        <td class="long"> 12.00-12.30 </td>
        <td class="long"> 12.30-13.00 </td>
        <td class="long"> 13.00-13.30 </td>
        <td class="long"> 13.30-14.00 </td>
        <td class="long"> 14.00-14.30 </td>
        <td class="long"> 14.30-15.00 </td>
      </tr>
      <tr>
        <th class="headcol"> Jack </th>
        <td class="long"></td>
        <td class="long"></td>
        <td></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
        <td class="long"></td>
      </tr>
    </table>
    </div>

    【讨论】:

      【解决方案2】:

      试试下表示例

      jQuery(document).ready(function() {
         jQuery(".main-table").clone(true).appendTo('#table-scroll').addClass('clone'); 
          });
      .table-scroll {
          position:relative;
          max-width:1024px;
          margin:auto;
          overflow:hidden;
      }
      
      .table-wrap {
          width:100%;
          overflow:auto;
      }
      .table-scroll table {
          width:100%;
          margin:auto;
          border-collapse:separate;
          border-spacing:0;
      }
      .table-scroll th, .table-scroll td {
          padding:5px 10px;
          background:#fff;
          white-space:nowrap;
          vertical-align:top;
      
      }
      .table-scroll thead, .table-scroll tfoot {
          background:#f9f9f9;
      }
      .clone {
          position:absolute;
          top:0;
          left:0;
          pointer-events:none;
      }
      .clone th, .clone td {
          visibility:hidden
      }
      .clone td, .clone th {
          border-color:transparent
      }
      .clone tbody td:first-child {
          visibility:visible;
          color:black;
      }
      .clone .fixed-side {
          visibility:visible;
      }
      .clone thead, .clone tfoot{background:transparent;}
      <div id="table-scroll" class="table-scroll">
        <div class="table-wrap">
          <table class="main-table table table-bordered">
      
            <tbody>
              <tr>
                <th colspan="15" class="fixed-side"> Thu 05 th Apr, 2018</th>
      
              </tr>
              <tr>
                <th class="fixed-side">Date</th>
                <td> 08.00-08.30 </td>
          <td> 08.30-09.00 </td>
          <td> 09.00-09.30 </td>
          <td> 09.30-10.00 </td>
          <td> 10.00-10.30 </td>
          <td> 10.30-11.00 </td>
          <td> 11.00-11.30 </td>
          <td> 11.30-12.00 </td>
          <td> 12.00-12.30 </td>
          <td> 12.30-13.00 </td>
          <td> 13.00-13.30 </td>
          <td> 13.30-14.00 </td>
          <td> 14.00-14.30 </td>
          <td> 14.30-15.00 </td>
              </tr>
              <tr>
                <th class="fixed-side">Name</th>
                <td>jack</td>
               <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
                <td>jack</td>
              </tr>
      
            </tbody>
      
          </table>
        </div>
      </div>
      <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-03
        • 2022-01-21
        • 2018-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-20
        • 1970-01-01
        相关资源
        最近更新 更多