The Table header and the Table data cells are not aligned and are not properly fitting within the table dimensions

Is there a way to adjust the code below so that the Table THead aligns with the TD's and maintains the width of the table? The current issue is that the table headers are extending beyond the div size, causing the table to span horizontally across the page.

<!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 -->

        <!-- Rest of the table body content omitted for brevity -->

    </tbody>
    <!-- Table Body -->

</table>
  <script>
  $(function() {
    $( "#data tr th" ).resizable({
      handles: 'e'
    });
  });
  </script>
</div>

</body>
</html>

ETA http://jsfiddle.net/KrB79/

Answer №1

Update the CSS styling for the container to:

.container {
    width: 98%;
    height: 350px;
    overflow-x: scroll;
    overflow-y: scroll;

    position: absolute;
}

This should resolve any issues with Internet Explorer 7.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to activate an ASP.NET LinkButton using JavaScript

I've set up a page to hide a FileUpload control, so that when a button is clicked, it displays the file upload window and automatically submits the selected file to the server. To make this work, I created two linkbuttons and a file upload control, b ...

Implementing multi-select checkbox feature in Angular 7 using ng-select

I'm looking to create a function where selecting an item will make the corresponding div appear. For instance, if I choose Crédit bancaire and Compte courant associé, the two corresponding divs should be shown. Check out this example: https://stac ...

Leveraging service.ts data across multiple components

In my implementation, I have a next.service.ts file with 3 variables (user, action, rest) and created setters (updateNext()) and getters (getUser, getAction, getRest). I tried using the setter to modify the variables in one component (stock-management comp ...

Creating an overlapping HTML/CSS div within a parent div

After successfully building numerous websites and fixing various issues along the way, I now find myself stuck on a particular problem. Despite my experience, I can't seem to figure it out this time. The issue lies within a wrapper div that contains ...

Parsing HTML in PHP from a specified URL

I am a newcomer to PHP and have been trying to parse HTML with it. Despite my efforts, I have not been able to get any examples to work. I attempted using the "SimpleHTMLDom" library but am willing to try anything as long as clear instructions are provided ...

IE 11 is giving me trouble with max-width functionality

As a new designer, I recently created my own WordPress theme that functions perfectly on FireFox, Chrome, and Opera. However, I encountered an issue with InternetExplorer (I'm using Windows 7 with IE 11). It appears that InternetExplorer 11 does not ...

AngularJS: Showcase HTML code within ng-view along with its corresponding output displayed in a navigation format such as Html, Css, JS, and Result

Currently, I am working on a web application. One of the screens, screen-1, consists of a series of buttons labeled 'Code'. When a user clicks on any of these buttons, it loads a different HTML page, screen-2, in the ng-view using $location.path( ...

Showing the values of selected checkboxes in a select dropdown - here's how!

Link to the jsfiddle : https://jsfiddle.net/a1gsgh11/9/ The JavaScript code seems to not be working on the js fiddle platform. My main concern is that I would like the selected checkbox values to display immediately without needing to submit any buttons. ...

Tips to prevent caching in the web console while reviewing the code document

Currently troubleshooting a PHP file with a syntax error using Firefox web console. I ensured the Disable Cache option is set and observed that changes to the file take effect immediately. However, despite displaying the syntax error in the console, clicki ...

Presenting titles and buttons within a Bootstrap modal window

I have implemented a modal using vue-bootstrap. The code for the modal is as follows: <template id="child"> <b-modal v-model="showModal" size="lg"> <template v-slot:modal-header> <h4 class="modal-title"> ...

Modal footer obstructing popover in modal body

I'm facing an issue with a Bootstrap 4 modal that contains buttons, one of which is supposed to trigger a custom popover div centered below it. The popover works fine outside the modal, but within the modal, it's partially hidden. After trying v ...

Creating a table with a tableHead cell comprised of multiple components in ReactJS/CSS using Material UI

It's possible that the title lacks description. I am attempting to generate a table with a specific layout like this https://i.sstatic.net/T97C2.gif Essentially, the "Average" cell is combined with two smaller cells for "height" and "width," which c ...

Combining CSS Selectors

Can you combine these selectors into one for ul#footer_navigate: ul#social_footer li a:link, ul#social_footer li a:visited {} I would like the same selector to apply for both anchor states on the ul with ID #footer_navigate. Is there a different approac ...

Display a customized hyperlink in HTML

I have a query regarding embedding HTML data in my own domain link. I want to set it up so that when I open the link, a webpage displays with the HTML script without requiring me to download the HTML file directly. I believe this can be achieved using a P ...

How to Retrieve HTML Content from an Azure Function Using C#

I created an Azure function using C# that generates HTML content. However, when I access it from a web browser, the response is displayed as plain text instead of rendering as HTML. After some research, it seems like I need to define the ContentType header ...

Angular component: Placing icons on the right side of a mat-chip element

My mat-chip contains content and a cancel icon, but I am having trouble getting the cancel icon to float to the right consistently. Despite setting a fixed width for the mat-chip, the cancel icon is not aligning properly no matter what CSS techniques I t ...

Uncover each image individually

I have a task in React where I am displaying a list of images using the map method, and I want to reveal each image one by one after a delay. The images I am working with can be seen here and I need them to be revealed sequentially. The following code sni ...

JavaScript: Retrieving the following element from the parent container

Is there a way to prevent the next element within the parent tag from being enabled or disabled based on a certain condition? HTML: <span> <input type="checkbox" onchange="toggleInput(this)"> </span> <input type="text" ...

Invoke the JavaScript function on the HTML button click event, sending the ASP parameter

Currently, I am working with node and passing a parameter in the following manner: res.render('page.ejs',{"product" : product }); The paramter 'product' is in JSON format. Within the 'page.ejs' file, I am attempting to call ...

What could be causing my CSS menu to occasionally display incorrectly?

I'm currently facing a challenge with the main menu on my website. Occasionally, about 1 out of every 10 times, the menu fails to load correctly. Please see the images below for comparison! This is how the menu is intended to appear: ...and this i ...