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 6330729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:55:27+00:00 2026-05-24T17:55:27+00:00

I want a scrollable table. To achieve that, I wrap a <table> into a

  • 0

I want a scrollable table. To achieve that, I wrap a <table> into a <div> with a max-height and overflow: auto. In addition, the <div> has display: inline-block to ensure that the div adjusts its width to the underlying table.

<html>
<head>
    <title>Test</title>
    <style type="text/css">
        div { max-height: 100px; display: inline-block;
              overflow: auto; border: 1px solid red; }
        td { border-bottom: 1px solid black; }
    </style>
</head>
<body>
    <div>
        <table>
            <tr><td>bla bla bla bla bla</td></tr>
            <tr><td>bla bla bla bla bla</td></tr>
            <tr><td>bla bla bla bla bla</td></tr>
            <tr><td>bla bla bla bla bla</td></tr>
            <tr><td>bla bla bla bla bla</td></tr>
            <tr><td>bla bla bla bla bla</td></tr>
            <tr><td>bla bla bla bla bla</td></tr>
        </table>
    </div>
</body>
</html>

In most browsers (Firefox, Safari, Chrome), this causes a problem: If the table is longer than 100px, vertical scroll bars are added without making the div wider, causing the text to wrap:

Firefox screenshot

In IE it looks “correct”:

IE screenshot

Is there a way to fix this?

  • 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-05-24T17:55:27+00:00Added an answer on May 24, 2026 at 5:55 pm

    http://jsfiddle.net/3VSZE/44/

    So whats happening is BEFORE the scroll bar is rendering, it is setting the width of the table == width of the containing div. So, for conversations sake, lets say the width of the div is 100px and the width of the scroll bar is 10px, and the width of the inner table is 100px. When the browser is trying to render the div, it assumes a total width of 100px. It then goes along its merry way rendering the contents of the div. Then the scroll bar is added and the contents of the div now have a total width of 110px (table + scroll bar) but the width of the div is still 100px. So basically, the browser is trying to render 110px inside a 100px container, causing the wrap that you’re seeing.

    That is why adding a second div, and then giving that div a margin so the scroll bar will fit, works. I gave this a shot in IE8 and it doesn’t add extra space (like I originally thought it would). Its worth noting that when you do this in compatibility mode, the div takes up the entire width of the page. This happens in my example, and with yours. I don’t know how to fix that; but that is off topic for this question. I didn’t have time to give IE7 a shot.

    This is a little bit cleaner and also that it works when the content of one of the rows is much wider:

    http://jsfiddle.net/3VSZE/75/

    <html>
    <head>
        <title>Test</title>
        <style type="text/css">
            .a { border: 1px solid red; display: inline-block; }
            .b { width: 100%; overflow: auto; max-height:100px; margin-right: 18px; }
            td { border-bottom: 1px solid black; }
        </style>
    </head>
    <body>
        <div class="a">
            <div class="b">
                <table>
                    <tr><td>bla bla bla bla bla</td></tr>
                    <tr><td>bla bla bla bla bla</td></tr>
                    <tr><td>bla bla bla bla bla</td></tr>
                    <tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
                    <tr><td>bla bla bla bla bla</td></tr>
                    <tr><td>bla bla bla bla bla</td></tr>
                    <tr><td>bla bla bla bla bla</td></tr>
                </table>
            </div>
        </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a scrollable div tag with a fixed height that gets
I want a scrollable ( overflow: auto ) div element to be completely contained
On my web page, I a table inside a DIV that is scrollable. When
I have a div that is scrollable that I want to conditionally stop scrolling.
I want to put a scrollable EditText above a row of buttons such that
I want to create a scrollable list of pictures fetched from the internet and
I want to know the bounds of the grey scrollable area in an MDI
want to have a Hyperlink-Button in a gridView in which I can display a
Want the function to sort the table by HP but if duplicate HPs then
I have a table which has many columns and lots of records. My user

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.