HTML / CSS - 右侧的Frozen Table Column

时间:2012-11-14 12:15:49

标签: html css css-tables

我在这里找到了固定/冻结左栏的解决方案:http://jsfiddle.net/emn13/YMvk9/

    body { font:16px Calibri;}
    table { border-collapse:separate; border-top: 3px solid grey; }
    td {
        margin:0;
        border:3px solid grey; 
        border-top-width:0px; 
        white-space:nowrap;
    }
    div { 
        width: 600px; 
        overflow-x:scroll;  
        margin-left:5em; 
        overflow-y:visible;
        padding-bottom:1px;
    }
    .headcol {
        position:absolute; 
        width:5em; 
        left:0;
        top:auto;
        border-right: 0px none black; 
        border-top-width:3px; /*only relevant for first row*/
        margin-top:-3px; /*compensate for top border*/
    }
    .headcol:before {content: 'Row ';}
    .long { background:yellow; letter-spacing:1em; }​

但是,如果没有Javascript或其他重叠表,是否也可以获得正确固定/冻结列?

2 个答案:

答案 0 :(得分:9)

更改下面的CSS

 div { 
            width: auto; 
            overflow-x:scroll;  
            margin-right:5em; 
            overflow-y:visible;
            padding-bottom:1px; 
        }
        .headcol {
            position:absolute; 
            width:5em; 
            right:0;
            top:auto;
            border-right: 0px none black; 
            border-top-width:3px; /*only relevant for first row*/
            margin-top:-3px; /*compensate for top border*/
        }
        .headcol:after{content: 'Row ';}

DEMO

答案 1 :(得分:0)

这是你在找什么?我只做了一排。您可以根据需要添加任意数量的行。检查以下HTML和样式。

<div><table>
        <tr><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
    <td class="headcol">1</td></tr>
</table></div>

​

        body { font:16px Calibri;}
        table { border-collapse:separate; border-top: 3px solid grey; }
        td {
            margin:0;
            border:3px solid grey; 
            border-top-width:0px; 
            white-space:nowrap;
        }
        div { 
            width: 600px; 
            overflow-x:scroll; 
            overflow-y:visible;
            padding-bottom:1px;
        }
        .headcol {
            position:absolute; 
            width:5em; 
            right:0;
            top:auto;
            border-right: 0px none black; 
            border-top-width:3px; /*only relevant for first row*/
            margin-top:-3px; /*compensate for top border*/
        }
        .headcol:before {content: 'Row ';}
        .long { background:yellow; letter-spacing:1em; }​