I'd like to use the CSS3 flexbox model to create a cross-device layout and found a nice example layout by HugoGiraudel which I used as a starting point.
The layout basically looks like this:
Here is the structure of the HTML:
<div class="wrapper">
<header class="header">Header</header>
<article class="main">
...
</article>
<aside class="aside aside-1">Aside 1</aside>
<aside class="aside aside-2">Aside 2</aside>
<footer class="footer">Footer</footer>
</div>
Here the most important parts of the CSS:
.wrapper {
display: flex;
flex-flow: row wrap;
}
.wrapper > * {
padding: 10px;
flex: 1 100%;
}
.aside { flex: 1 auto; }
.main { flex: 3 0px; }
My problem is when the article contains more content than fits on the screen, a vertical scrollbar appears next to the outer .wrapper
and the footer isn't visible any more.
I tried to add overflow: scroll
and flex-flow: column wrap
to the article's styling, but without success - the scrollbars are visible but the article always grows to completely enclose its contents.
How can I keep the footer visible and the article scrolling if the contents grow?
The reason your article content expands the whole layout is that it doesn't have any height limitation. Something like
max-height
would limit its growth, and then a vertical scrollbar could appear.Here's your code with a few adjustments:
HTML (added a nested flex container for article and asides)
CSS (key adjustments only)
Revised Codepen
NOTES:
.wrapper
) has three flex items stacked vertically.flex: 1
). The middle flex item (.inner-wrapper
) is confined to 50%, which enables scrolling. Try 25% and 75% for alternative examples.