我想创建一个表格网格,其中前几列是固定的,其余部分是可滚动的,如此图所示.
其余列是动态的,用户可以选择和取消选择列.我正在努力使用div或表格制作html.需要指导或样本结构继续前进.
具有自定义实现。就像这样简单:
table {
table-layout: fixed;
width: 100%;
*margin-left: -100px;/*ie7*/
}
td, th {
vertical-align: top;
border-top: 1px solid #ccc;
padding:10px;
width:100px;
}
.col1{
position:absolute;
*position: relative; /*ie7*/
left:0;
width:100px;
}
.col2{
position:absolute;
*position: relative; /*ie7*/
left:100px;
width:100px;
}
.col3{
position:absolute;
*position: relative; /*ie7*/
left:200px;
width:100px;
}
.col4{
position:absolute;
*position: relative; /*ie7*/
left:300px;
width:100px;
}
.outer {position:relative}
.inner {
overflow-x:scroll;
overflow-y:visible;
width:500px;
margin-left:400px;
}Run Code Online (Sandbox Code Playgroud)
<div class="outer">
<div class="inner">
<table>
<tr>
<th class="col1">Header A</th>
<th class="col2">Header A</th>
<th class="col3">Header A</th>
<th class="col4">Header A</th>
<td>col 2 - A (WITH LONGER CONTENT)</td>
<td>col 3 - A</td>
<td>col 4 - A</td>
<td>col 5 - A</td>
<td>col 6 - B</td>
<td>col 7 - B</td>
</tr>
<tr>
<th class="col1">Header B</th>
<th class="col2">Header B</th>
<th class="col3">Header B</th>
<th class="col4">Header B</th>
<td>col 2 - B</td>
<td>col 3 - B</td>
<td>col 4 - B</td>
<td>col 5 - B</td>
<td>col 6 - B</td>
<td>col 7 - B</td>
</tr>
<tr>
<th class="col1">Header C</th>
<th class="col2">Header C</th>
<th class="col3">Header C</th>
<th class="col4">Header C</th>
<td>col 2 - C</td>
<td>col 3 - C</td>
<td>col 4 - C</td>
<td>col 5 - C</td>
<td>col 6 - B</td>
<td>col 7 - B</td>
</tr>
</table>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
或jsfiddle:
https://jsfiddle.net/h75zn59o/21/
注意:
position:absolute; 是什么导致该第一标题列被固定。
对于原始CSS,它仅适用于“ th”,但使用类(在此示例中为col1,col2等)。
我们可以将不同的固定位置分配给不同的列。
由于列的宽度为100px,因此每隔一列再左移100px,因此第一列为0px,col2为100px,以此类推),以避免与前一列重叠。
| 归档时间: |
|
| 查看次数: |
1549 次 |
| 最近记录: |