9

I'm developing a site with a blog section. I need this section to have a fixed height. In order to be able to see all the posts in the blog I added an overflow: auto so it shows a scrollbar when needed.

<div id="container">
<div id="content">
    <div class="post">
         This is a long post....
    </div>
    <div class="post">
        This is a long post....
    </div>
    <div class="post">
        This is a long post....
    </div>
    ....
    ....
    ....
    ....
</div>
</div>

#container {
    overflow: hidden;
}

#content {
    height: 200px;
    overflow: auto;
    border: 1px solid red;
}

.post {
    margin: 20px 0;
}

I tested this on Chrome, Firefox and IE. The site on Firefox and IE works as expected, but Chrome, although it shows a scrollbar when the list of posts is bigger than the container, adds a white gap the size of the list of posts under the container.

I created a fiddle but I can't reproduce the Chrome behavior there:

http://jsfiddle.net/u5d56/3/

Using overflow: scroll instead of auto gives me the same results.

Any ideas?

Thanks in advance

1
  • 4
    If you can't reproduce it in a jsFiddle, then you probably have more code that's causing the issue. Also, what's the point of positing a fiddle that doesn't reproduce the problem?
    – j08691
    Commented Apr 6, 2014 at 18:51

2 Answers 2

20

I found the solution to my problem. For some reason, for this to work in Chrome I had to add a position:relative rule to #content:

#content{
    position: relative;
    height: 200px;
    overflow:visible;
    border 1px solid red;
}
4
  • OMG thank you! My issue was that the (horizontal) scrollbar seemed to sit under the next element and thus was not grabable. position: relative on the container fixed the issue.
    – Phil
    Commented Nov 12, 2015 at 3:04
  • ditto, same thing, scroll bar visible but only grabbable at one particular point. Was having trouble with code blocks in a <pre>.
    – Ron
    Commented Feb 14, 2016 at 0:31
  • 1
    Ran into something like this -- only on Chrome, and only on a retina display! I could actually drag my window to an attached 1x monitor, and watch the page repaint properly, but on the retina side, it would intermittently fail to paint most of the scrolling section. Seems like a straight-up bug, rather than a standards interpretation issue. In any case, your solution was a lifesaver.
    – johncip
    Commented Apr 23, 2016 at 0:41
  • 1
    I'd say your answer works not because of the position:relative but because of the overflow:visible which makes it never show a scrollbar.
    – bostero2
    Commented Jun 28, 2017 at 9:16
-1

A possible answer from HTML5 Application Development Fundamentals

#content{
     height: 200px;
     region-overflow:auto;
     overflow:visible;
     border 1px solid red;
}

Now this is gearing more towards responsive design. Add -webkit- before overflow might help since it is a chrome issue only. Assuming it is CSS3.

#content {
    height: 200px;
    overflow: auto;
    -webkit-overflow: auto;
    border: 1px solid red;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.