Matty
Matty

Reputation: 159

HTML / CSS - Frozen Table Column on the right side

I've found a solution for fixed/frozen left-column here: 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; }​

But is it also possible to get a right fixed/frozen column without Javascript or another overlaying table?

Upvotes: 13

Views: 10083

Answers (2)

Narendra
Narendra

Reputation: 3117

Is this what you are looking for? I made it for one rwo only. You can add as many rows as you want. Check the following HTML and style.

<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; }​

Upvotes: -1

Sowmya
Sowmya

Reputation: 26979

Change the css like below

 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

Upvotes: 11

Related Questions