Advertisement
  1. Web Design
  2. Responsive Web Design
Webdesign

How to Make Responsive, Scrollable Panels with Flexbox

by
Difficulty:IntermediateLength:ShortLanguages:

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.

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.

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.

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.

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
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.