Is there a way to connect the horizontal scrolling of a table header with the horizontal scrolling of a table body while keeping the vertical scrolling of the table body separate from the table header?

Looking for a solution that provides a fixed header and frozen pane within a table, similar to the example at . However, I need the header to scroll horizontally with the body of the table.

Here is an example based on the aforementioned link. The problem here is that the header does not follow the scrolling direction of the table's body.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <style type="text/css">
            .outer
            {
                position:relative;
                padding-top: 50px;
                border: 1px solid #0000ff;
            }
            .innera
            {
                overflow:auto;
                height: 100px;
                border: 1px solid #00ff00;
            }
            .outer thead tr
            {
                position:absolute;
                top: 0px;
                left:0;
            }
            .outer th, .outer td
            {
                text-align:left;
                white-space:nowrap;
            }
        </style>
    </head>
    <body>
        <div class="outer">
            <div class="innera">
                <table >
                    <thead>
                        <tr>
                            <th scope="col">FLIGHT CODE</th>
                            <th scope="col">FROM</th>
                            <th scope="col">STA</th>
                            <th scope="col">ETA</th>
                            <th scope="col" class="nd">Notes</th>
                        </tr>
                    </thead>

                    <tfoot>
                        <tr>
                            <td colspan="5">DATE : 19th OCTOBER 2005</td>
                        </tr>
                    </tfoot>

                    <tbody>
                        <tr>
                            <th scope="row">T3 4264</th>
                            <td>ISLE OF MAN</td>
                            <td>11:40</td>
                            <td>11:42</td>
                            <td>LANDED AT 11:43</td>
                        </tr>

                        <tr class="dk">
                            <th scope="row">BA 4081</th>
                            <td>PARIS-CDG</td>
                            <td>11:45</td>
                            <td>11:57</td>
                            <td>LANDED AT 11:58</td>
                        </tr>
                     <!-- Rest of the code omitted for brevity -->
                    
                </table>
            </div>
        </div>


    </body>
</html>

Answer №1

Update the overflow attribute to the specified value:

.innera
        {
            overflow:scroll; /*changed from auto to scroll*/
            height: 100px;
            border: 1px solid #00ff00;
        }

Answer №2

If you're looking for a solution, I found this after a quick search:

The explanation is detailed, so be sure to check out the source for a working example.

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

in JavaScript arrays, the identifier follows the numeric value right away

Can anyone assist me with assigning a PHP array of image filenames to a JavaScript array? I have made some progress, here's my code: <script src="jq.js"></script> <?php $dir = 'images'; $images = scandir($dir); $true_images ...

Tips for combining enable and disable properties in flatpickr.js?

I'm facing a challenge with using both the enable and disable properties in flatpickr.js. The enable property returns a range of dates that should be enabled, but I specifically want to disable certain days within that range, like weekends. datePicker ...

Unable to modify form within HTML modal

I am currently facing an issue with editing bootstrap forms. I have set a default and a placeholder value via js, however, the users are unable to change the textfield values. Below is the code for my modal. getData(){ // Pulls data from our API ...

The usage of THREE.MeshFaceMaterial has been deprecated and is no longer supported. It is advised to

I'm currently experimenting with wrapping images around a cube in three.js and encountering the error message 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' from my previous research, it seems like the method I am trying to ...

The width of the Bootstrap shadow container is not optimized for large viewports

Having recently started using bootstrap (less than six hours of documentation/development time), I encountered an issue where the width of my shadow container extends too far on smaller screen sizes. Any screen size above 991px leaves unwanted white space ...

Looking to display database information using javascript

Currently, I am working on a project involving PHP code where I retrieve variables from an input and utilize AJAX. Here is the code snippet: $.ajax({ type: "GET", url: "controller/appointment/src_agenda.php", data: { function: "professional", ...

Is there a functional way in JavaScript/ES6 to retrieve a specific object from an array based on its property or field value?

I've got a JavaScript array filled with objects, which in this case represent different countries pulled from JSON data via a web service: let countries = [ ..., { "id": 46, "type": "COUNTRY", ...

Retrieving table information using curl and regular expressions

Here is the code I have developed to extract data from a table on a specific website. However, I am looking to remove any links present in the data and also separate the title and price into an array. <?php $ch = curl_init("http://www.digionline.ir/ ...

Leveraging Axios within VueJS - the missing piece

When working with typescript and vuejs + axios, I have included the following .catch function on a post request to handle network errors and inform the user of the status: .catch(function(error) { console.error(error.response); ...

Using Cordova to create an accordion list on an HTML webpage

I am in need of an accordion list implementation for the given HTML code. I specifically want it to expand when 'Technical' is clicked, and collapse upon clicking again. Here is the HTML code: <!-- Techincal --> <div class= ...

Sending information from the Controller to a JavaScript function

Within my controller, the following code is present: public async Task<IActionResult> Index() { HttpResponseMessage responseMessage = await _httpClient.GetAsync(_getDataControlerApiUrl + "/getUserData"); string stringDat ...

Transferring data from JavaScript to ASP.NET (via AJAX)

I'm trying to figure out how to pass variables from JavaScript to a textbox. I have a variable in JavaScript but I am unsure how to transfer it to the textbox. I have heard that using AJAX makes it easy, but I don't know how to implement it. I th ...

Using an Ajax call within an event handler function

After spending a full day attempting to execute an AJAX call within an event handler function, I've tried various combinations of when(), then(), and done(), as well as setting async: false. However, I keep encountering undefined errors despite my eff ...

Can jQuery help me identify which <input type='image> was clicked within a form containing several submit images?

Consider this hypothetical scenario: <form> <input type="text" name="some_name" value="val" id="some_name"> <input type="image" value="action" alt="Add To Cart" name="add" src="/images/submit.gif"> <input type="image" value="act ...

Storing a Vue JS component as a string in a variable and displaying it using that variable

I am currently working on a project where I need to implement the following code snippet: <template v-for="(element, k) in place.data.content"> <data_elements[element.name].component></data_elements[element.name].component> </te ...

Update the select tag to display as radio buttons

Hey there, I've got a webpage where users can rate different systems. I've written a JavaScript function to dynamically add and remove systems for evaluation. The only issue is that I have to manually change the radio button names to prevent th ...

What causes the div to shift down first before smoothly sliding when attempting to conceal it using jQuery UI?

$(function() { $("button").on("click", function() { $("#test").hide("slide", { direction: "left" }, 2000) }); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https: ...

What sets window.scrollTo({top: 50}) apart from window.scrollTo(0, 50)?

Currently in a React function, I have implemented window.scrollTo(0, 50) instead of using window.scrollTo({top: 50}) to cater to older versions of Android that do not support passing an object to window.scrollTo. This change has proven successful as it scr ...

Internet Explorer not triggering jQuery blur() or focusout() events

Having some issues with my form and event handling when the inputs lose focus. The code is working perfectly in every browser except for Internet Explorer. function formstyle() { var focus = 0; //comentario is the ID of the input $("#comenta ...

Exploring an HTML document with XPath expressions

I am trying to query an HTML document using C# and XPath. I am specifically looking for an XPath expression, without any language-specific code samples like XSLT or PHP. Any assistance with providing the XPath expression would be greatly appreciated :). & ...