Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    182
    Thanks
    139
    Thanked 0 Times in 0 Posts

    Table Thead Does not match up with TD Cells and Does not respect the table size

    Hello,

    I need the help of the experts here on this forum.

    How can the code below be modified such that the Table THead matches up with the TD's and also respect the size (width) of the table? What is happening now is that the table headers expand beyond the size of the div and the table horizontally accross the page.

    Code:
    <!DOCTYPE html>
    <html>
    <head>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
    
    <style type="text/css">
    
    /*------------------------------------------------------------------
    Table Style
    ------------------------------------------------------------------ */
    table a:link {
        color: #666;
        font-weight: bold;
        text-decoration:none;
    }
    table a:visited {
        color: #999999;
        font-weight:bold;
        text-decoration:none;
    }
    table a:active,
    table a:hover {
        color: #bd5a35;
        text-decoration:underline;
    }
    table {
        font-family:Arial, Helvetica, sans-serif;
        color:#666;
        font-size:12px;
        background:#eaebec;
        border-radius:3px;
        border-collapse:collapse; border-spacing: 0; 
        box-shadow: 0 1px 2px #d1d1d1;
        border-left: 1px solid #ccc;
        border-right: 1px solid #ccc;
        table-layout: fixed;
    
    
    }
    table th {
        border-bottom:1px solid #ccc;
        border-left: 1px solid #ccc;
        background: #ededed;
    }   
    table tr {
        text-align: center;
    }   
    table td {
        border-bottom:1px solid #ccc;
        border-left: 1px solid #ccc;
        background: #fafafa;
            text-align: left;
    }   
    table tr:hover td {
        background: #f2f2f2;
    }
    table th, table td {
        height: 20px;
        width: 200px;
    }
    #container {
        width : 98.7%;
        height: 300px;
        overflow-x: scroll;
        overflow-y: scroll;
    }
    table tr td:first-child, table tr th:first-child {
        border-left: 0;
    }
    
    table thead {
        _position: fixed;
        _position: relative;
        _position: absolute;
    
    }
    
    TABLE THEAD TR TH {
        top:expression(this.offsetParent.scrollTop);
        border-top:1px solid #ccc;
        _position:relative;
        _position: absolute;
        _position: fixed;
    }
    
    table tr:first-child td {
        border-top: 0;
    }
    </style>
    
    </head>
    
    <body>
    
    <div id="container">
    
    <table id="data">
    
        <!-- Table Header -->
        <thead>
            <tr>
                <th>File Number</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>Firstname</th>
                <th>Lastname</th>
                <th>Progress</th>
                <th>Vital Task</th>
            </tr>
        </thead>
        <!-- Table Header -->
    
        <!-- Table Body -->
        <tbody>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>100%</td>
                <td>Yes</td>
            </tr><!-- Table Row -->
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>100%</td>
                <td>Yes</td>
            </tr><!-- Darker Table Row -->
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>20%</td>
                <td>No</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>80%</td>
                <td>No</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>100%</td>
                <td>Yes</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>23%</td>
                <td>yes</td>
            </tr>
    
            <tr>
                <td>ABC-123-123456</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>80%</td>
                <td>No</td>
            </tr>
    
            <tr>
                <td><a href="#yep-iit-doesnt-exist">Hyperlink Example</a></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>80%</td>
                <td><a href="#inexistent-id">Another</a></td>
            </tr>
    
        </tbody>
        <!-- Table Body -->
    
    </table>
      <script>
      $(function() {
        $( "#data tr th" ).resizable({
          handles: 'e'
        });
      });
      </script>
    </div>
    
    </body>
    </html>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    get rid of all the _position lines.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •