Wednesday, 12 April 2017

Fixed Header Scrollable Html Table Using CSS


Introduction
In this post we will learn how to create scrollable Html table with fixed header with the help of css. Css has many properties through which we can achieve this task easily.

Have a Look
In previous articles we already done similar work with grid. Display data in Asp GridView in tabular form. Change grid view row color based on condition dynamically. Display progress image on Button click. 

Practice
If you are working with asp.net application then add a simple Html form or you can do this same task with your aspx page. Here is my code for Html page with CSS.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Scrollable HTML table with CSS Style</title>
    <style type="text/css">
        table {
            border-spacing0;
            width100%;
        }
        td + td {
            border-left1px solid #000;
        }
        tdth {
            border-bottom1px solid #000;
            background#fff;
            color#000;
            padding10px 25px;
        }
        th {
            height0;
            line-height0;
            padding-top0;
            padding-bottom0;
            colortransparent;
            bordernone;
            white-spacenowrap;
        }
            th div {
                positionabsolute;
                backgroundtransparent;
                color#fff;
                padding9px 25px;
                top0;
                margin-left-25px;
                line-heightnormal;
                border-left1px solid #800;
            }
       section {
            positionrelative;
            border1px solid #000;
            padding-top37px;
            background#000099;
            width40%;
        }
        .Maincontainer {
            overflow-yauto;
            height200px;
        }
    </style>
</head>
<body>
    <form id="form1">
        <section class="">
            <div class="Maincontainer">
                <table>
                    <thead>
                        <tr class="header">
                            <th>Visitors Name<div>Visitors Name</div></th>
                            <th>Location<div>Location</div></th>
                            <th>Email<div>Email</div></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Mark Zuck</td>
                            <td>USA</td>
                            <td>mark@fb.com</td>
                        </tr>
                        <tr>
                            <td>Jack Dorsey</td>
                            <td>USA</td>
                            <td>jack@tw.com</td>
                        </tr>
                        <tr>
                            <td>Williamson</td>
                            <td>UK</td>
                            <td>will@gmail.com</td>
                        </tr>
                        <tr>
                            <td>Narendra Modi</td>
                            <td>India</td>
                            <td>modiji@hotmail.com</td>
                        </tr>
                        <tr>
                            <td>SRK King</td>
                            <td>India</td>
                            <td>srk@gmail.com</td>
                        </tr>
                        <tr>
                            <td>Reyna Seen</td>
                            <td>Virginia</td>
                            <td>ryna@gmail.com</td>
                        </tr>
                        <tr>
                            <td>Seen Paul</td>
                            <td>USA</td>
                            <td>seen@gmail.com</td>
                        </tr>
                        <tr>
                            <td>Dom</td>
                            <td>USA</td>
                            <td>dom@dom.com</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>
    </form>
</body>
</html>


Hope you familiar with CSS and this post will be really helpful for you.  Here is the output



No comments:

Post a Comment