Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:53:01+00:00 2026-06-09T01:53:01+00:00

I know, there are at least 3 dozen questions like this on stackoverflow and

  • 0

I know, there are at least 3 dozen questions like this on stackoverflow and still, I could not make this happen:

A simple table where thead is sticked/fixed at the top, and the tbody is scrolled.
I tried so much in the past days and now I ended up here crying for help.

A solution should work in IE8+ and newest FF, Chrome & Safari.
The difference to other “possible duplicates like this one is that I don’t want to use two nested tables or jQuery (plain javascript is fine though).

Demo of what I want:
http://www.imaputz.com/cssStuff/bigFourVersion.html.

Problem is it doesn’t work in IE, and I would be fine to use some JS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:53:03+00:00Added an answer on June 9, 2026 at 1:53 am

    Ok i got it:

    You need to wrap the table in two DIVs:

    <div class="outerDIV">
      <div class="innerDIV">
        <table></table>
      </div>
    </div>
    

    The CSS for the DIVs is this:

    .outerDIV {
      position: relative;
      padding-top: 20px;   //height of your thead
    }
    .innerDIV {
      overflow-y: auto;
      height: 200px;       //the actual scrolling container
    }
    

    The reason is, that you basically make the inner DIV scrollable, and pull the THEAD out of it by sticking it to the outer DIV.

    Now stick the thead to the outerDIV by giving it

    table thead {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
    }
    

    The tbody needs to have display: block as well.

    Now you’ll notice that the scrolling works, but the widths are completely messep up. That’s were Javascript comes in.
    You can choose on your own how you want to assign it. I for myself gave the TH’s in the table fixed widths and built a simple script which takes the width and assigns them to the first TD-row in the tbody.

    Something like this should work:

    function scrollingTableSetThWidth(tableId)
    {
        var table = document.getElementById(tableId);
    
        ths = table.getElementsByTagName('th');
        tds = table.getElementsByTagName('td');
    
        if(ths.length > 0) {
            for(i=0; i < ths.length; i++) {
                tds[i].style.width = getCurrentComputedStyle(ths[i], 'width');
            }
        }
    }
    
    function getCurrentComputedStyle(element, attribute)
    {
        var attributeValue;
        if (window.getComputedStyle) 
        { // class A browsers
            var styledeclaration = document.defaultView.getComputedStyle(element, null);
            attributeValue = styledeclaration.getPropertyValue(attribute);
        } else if (element.currentStyle) { // IE
            attributeValue = element.currentStyle[vclToCamelCases(attribute)];
        }
        return attributeValue;
    }
    

    With jQuery of course this would be a lot easier but for now i was not allowed to use a third party library for this project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there is no finder built into django for this (at least not
I know there is already at least a dozen valgrind reports invalid read questions,
I know there are a lot of questions around on this subject, but I've
I know there are dozens of questions that ask about this error, but none
Even though i know there are at least 2 or 3 topics with this
I know there are at least three popular methods to call the same function
I know there have been many questions on grid and pack in the past
I know there are lots of tools on the net that can make our
I know there is a lot on this topic but I can't get any
I know there are a lot of similar questions on SF, but I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.