【问题标题】:html table horizontal scroll enabling for specific columnshtml表格水平滚动启用特定列
【发布时间】:2020-01-29 11:55:26
【问题描述】:

让我们考虑下图。我正在生成员工工作时间的月度报告。当水平滚动条向右移动时,我希望code,name, area, territory 列固定在其位置,并且日期列应该是水平滚动的。向右滚动时,日期列应位于 code,name, area, territory 列组下方。我该怎么做?有没有可用的 css 技巧或插件?

【问题讨论】:

标签: javascript html css


【解决方案1】:

我认为根据@Circuit Breaker answer 修复列的​​最简单和合乎逻辑的方法是

.view {
  margin: auto;
  width: 600px;
}

.wrapper {
  position: relative;
  overflow: auto;
  border: 1px solid black;
  white-space: nowrap;
}

.sticky-col {
  position: sticky;
  position: -webkit-sticky;    
  background-color: white;
}

.first-col {
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  left: 0px;    
}

.second-col {
  width: 150px;
  min-width: 150px;
  max-width: 150px;
  left: 100px;    
}
<div class="view">
  <div class="wrapper"> 
    <table class="table">
      <thead>
        <tr>
          <th class="sticky-col first-col">Number</th>
          <th class="sticky-col second-col">First Name</th>
          <th>Last Name</th>
          <th>Employer</th>
       </tr>
      </thead>
       <tbody>
       <tr>
         <td class="sticky-col first-col">1</td>
         <td class="sticky-col second-col">Mark</td>
         <td>Ham</td>
         <td>Micro</td>
       </tr>
       <tr>
         <td class="sticky-col first-col">2</td>
         <td class="sticky-col second-col">Jacob</td>
         <td>Smith</td>
         <td>Adob Adob Adob AdobAdob Adob Adob Adob Adob</td>
       </tr>
       <tr>
         <td class="sticky-col first-col">3</td>
         <td class="sticky-col second-col">Larry</td>
         <td>Wen</td>
         <td>Goog Goog Goog GoogGoog Goog Goog Goog Goog Goog</td>
       </tr>
      </tbody>
    </table>
  </div>
</div>  

【讨论】:

  • 这是我在 stackoverflow 上找到的最佳解决方案。
猜你喜欢
  • 2017-01-05
  • 1970-01-01
  • 2011-03-25
  • 2011-10-25
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 2017-05-23
  • 1970-01-01
相关资源
最近更新 更多