Skip to content Skip to sidebar Skip to footer

Fixed Header/footer + Content Height 100% Cause Undesired Vertical Scrolling

I am trying to achieve a a horizontal scrolling website with a fixed header and footer. Goals: 1. Fixed Header and Footer 2. No vertical scrolling 3. Content div fills all spac

Solution 1:

Hmmm, the problem is that the wrapper(s) around your content between the header and footer are taking on the height of the viewport with height:100%. So, when you apply a margin to vertically offset those content wrappers (so that the header becomes visible), they get pushed by that much below the viewport (50px, height of the header). As a result, you get a vertical scrollbar, since the content wrappers are both the full height of the viewport and pushed down - so they can't fit on-screen.

How to avoid this? Well, if your footer and header height won't be dynamic (ie. You'll always be in control of how tall they are through your CSS), you can achieve this in a fairly straightforward manner with position:absolute.

Your structure I modified slightly; I removed the #2 and #b elements, since it looks like they were just there to properly position/size #bb, the actual content-containing element:

<divid="total"><headerid="1"><divid="a"><h1>Header</h1></div></header><divid="bb"><h2>Post Title Example One</h2><p>hello world! Have you thoroughly searched for an answer before asking your question?</p></div><footerid="3"><divid="c"><h1>footer</h1></div></footer></div>

Now, with your CSS, I removed the definitions for styling #2 and #b. Additionally, I modified the #bb CSS to read as:

#bb {
    position: absolute;
    top: 50px;
    bottom: 25px;
    width: 2000px;
    background-color: yellow;
}

Here's an updated JSFiddle to demonstrate what this achieves. Additionally, here's a JSFiddle implementing your multiple-row layout which you gave as a comment in one of the answers.

The reason why overflow:hidden doesn't quite work is because #bb would actually still extend below the viewport - just, no vertical scrollbar would be created because that overflowing region is ignored by the browser. However, when you use a percentage height, it becomes apparent that the height of #bb is not that which is visible. Anyways, hope this helps out! If this isn't what you were looking for, let me know and I'll be happy to help further. Good luck!

Solution 2:

To hide the scrollbar use:

overflow: hidden;

However, the text needs to go somewhere (otherwise it will be hidden), so you need to have the container larger or use text-columns.

Do you intend to achieve something like Windows 8 Metro UI for the scrolling?

Post a Comment for "Fixed Header/footer + Content Height 100% Cause Undesired Vertical Scrolling"