Advertisement
  1. Web Design
  2. UX/UI
  3. Responsive Design

How to Make Responsive, Scrollable Panels with Flexbox

Scroll to top

If you’ve been keeping up with the work ZURB has been doing with Foundation for Apps you may have noticed most of their demo templates have some pretty nifty scrollable panels.

These are actually pretty amazing–especially for hybrid apps. Remember how handy frames were before they went out of style? Well, now you can have that functionality back, but in a responsive way.

After some tinkering I was able to pull out the base functionality of these panels and that’s what we’ll be learning how to recreate today.

1. Begin at the Beginning

We’ll start with some pretty basic markup. The most important part is a wrapping container to wrap your entire page.

1
<div class="wrap">
2
3
  <main>
4
5
    <aside>
6
      <h1>Sidebar</h1>
7
      <p>
8
        lipsum...
9
      </p>
10
    </aside>
11
12
    <article>
13
      <h1>Content</h1>
14
      <p>
15
        lipsum...
16
      </p>
17
    </article>
18
19
  </main>
20
21
</div>

2. CSS

Things get interesting in the CSS pretty quickly. First, we want our html and body selectors to be height: 100%. We’re doing this to set up the .wrap element which we’ll set to height: 100vh. With the vh unit we’re saying that we want this app to take up the full height of the viewport so the elements contained within it will be forced to scroll. 

We’ll also set .wrap to be display: flex so we can give children elements a flex property.

1
html, body {
2
  height: 100%;
3
}
4
5
.wrap {
6
  height: 100vh;
7
  display: flex;
8
}

Note: Instead of remembering all the various syntaxes for Flexbox throughout the years, try using Autoprefixer. Then you just need to use the W3C spec syntax and it will do the rest to support as many browsers as possible.

3. Getting Flexible

Now that we have this “shell” set up we can begin styling very standard flex elements into it. The only trick is to make sure you set these children elements to overflow-y: scroll to enforce a scrollbar.

1
main {
2
  flex: 1;
3
  display: flex;
4
}
5
6
aside, article {
7
  overflow-y: scroll;
8
  padding: 2em;
9
}
10
11
aside {
12
  flex: 1;
13
}
14
15
article {
16
  flex: 2;
17
}

4. Getting Responsive

Let’s take it one step further and make our site responsive by stacking the sidebar on top of the content area for smaller devices. It’s as easy as adding one CSS rule within a media query.

1
@media (max-width: 800px) {
2
  main {
3
    flex-direction: column;
4
  }
5
}

Conclusion

These steps should be enough to get you started using this technique throughout your websites. Now that I know how to do it, I’m finding all kinds of places to put these scrollable panels.

To see this in action properly, check out the demo on Codepen. Also, take a look at the unofficial Stylus redesign I built using this technique.

How do you see yourself using it?

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.