使用html div修复和Scrollable表结构

前端之家收集整理的这篇文章主要介绍了使用html div修复和Scrollable表结构前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想创建一个表格网格,其中前几列是固定的,其余部分是可滚动的,如此图所示.

其余列是动态的,用户可以选择和取消选择列.我正在努力使用div或表格制作html.需要指导或样本结构继续前进.

解决方法

使用自定义实现.就像这样简单:
  1. table {
  2. table-layout: fixed;
  3. width: 100%;
  4. *margin-left: -100px;/*ie7*/
  5. }
  6. td,th {
  7. vertical-align: top;
  8. border-top: 1px solid #ccc;
  9. padding:10px;
  10. width:100px;
  11. }
  12. .col1{
  13. position:absolute;
  14. *position: relative; /*ie7*/
  15. left:0;
  16. width:100px;
  17. }
  18. .col2{
  19. position:absolute;
  20. *position: relative; /*ie7*/
  21. left:100px;
  22. width:100px;
  23. }
  24. .col3{
  25. position:absolute;
  26. *position: relative; /*ie7*/
  27. left:200px;
  28. width:100px;
  29. }
  30. .col4{
  31. position:absolute;
  32. *position: relative; /*ie7*/
  33. left:300px;
  34. width:100px;
  35. }
  36. .outer {position:relative}
  37. .inner {
  38. overflow-x:scroll;
  39. overflow-y:visible;
  40. width:500px;
  41. margin-left:400px;
  42. }
  1. <div class="outer">
  2. <div class="inner">
  3. <table>
  4. <tr>
  5. <th class="col1">Header A</th>
  6. <th class="col2">Header A</th>
  7. <th class="col3">Header A</th>
  8. <th class="col4">Header A</th>
  9. <td>col 2 - A (WITH LONGER CONTENT)</td>
  10. <td>col 3 - A</td>
  11. <td>col 4 - A</td>
  12. <td>col 5 - A</td>
  13. <td>col 6 - B</td>
  14. <td>col 7 - B</td>
  15. </tr>
  16. <tr>
  17. <th class="col1">Header B</th>
  18. <th class="col2">Header B</th>
  19. <th class="col3">Header B</th>
  20. <th class="col4">Header B</th>
  21. <td>col 2 - B</td>
  22. <td>col 3 - B</td>
  23. <td>col 4 - B</td>
  24. <td>col 5 - B</td>
  25. <td>col 6 - B</td>
  26. <td>col 7 - B</td>
  27. </tr>
  28. <tr>
  29. <th class="col1">Header C</th>
  30. <th class="col2">Header C</th>
  31. <th class="col3">Header C</th>
  32. <th class="col4">Header C</th>
  33. <td>col 2 - C</td>
  34. <td>col 3 - C</td>
  35. <td>col 4 - C</td>
  36. <td>col 5 - C</td>
  37. <td>col 6 - B</td>
  38. <td>col 7 - B</td>
  39. </tr>
  40. </table>
  41. </div>
  42. </div>

或者jsfiddle:

https://jsfiddle.net/h75zn59o/21/

注意:

位置:绝对的;是什么原因导致第一个标题列被修复.

使用原始CSS,它只是应用于“th”,但使用类(在此示例中,col1,col2等)

我们可以为不同的列分配不同的固定位置.

因为列的宽度为100px,所以每个后续列位于另一个100px左侧,因此,第一个是0px,然后是colp的100px等,以避免与前一列重叠.

猜你在找的HTML相关文章