12

我在这里找到了固定/冻结左列的解决方案: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 或其他覆盖表的情况下获得正确的固定/冻结列?

4

2 回答 2

10

像下面这样更改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 ';}

演示

于 2012-11-14T12:25:24.673 回答
-1

这是你想要的?我只做了一个 rwo。您可以根据需要添加任意数量的行。检查以下 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; }​
于 2012-11-14T12:40:11.870 回答