Photo by James Pond on Unsplash

Nowadays, new devices are launched every day and users browse web apps on a multitude of screen sizes. To offer a great online experience to their users, it’s become essential for businesses to make their web apps responsive — i.e., be able to display nicely no matter the screen they appear on. Fortunately, new CSS tools were created in the past years to help create such flexible layouts. On the other hand, older browsers that do not support the most recent web technologies are still used widely. For instance, in the financial industries, lots of companies use Internet Explorer 11 daily.

Here comes flexbox to the rescue! Flexbox is a CSS3 layout model that solves usually tricky problems including how to position, center or dynamically resize elements on a page. It’s a tool modern enough to create responsive designs and old enough to be implemented in major browsers.

In this article, we’ll learn some of flexbox main properties by recreating two components from Airbnb’s website.

Notes:

I’ll be taking a desktop-first (“large screen-first”) approach which means that I will write the code for large screens and use media queries to adapt to smaller ones.

I’m using the React library instead of regular HTML, but the syntaxes are similar so don’t worry if you aren’t familiar with React!

Responsive navigation bar

The first element I recreated is Airbnb’s navigation bar. It applies the main use case of flexbox which is to layout elements inside a container in any direction.

Let’s take a look at the final result: on large screens, page links appear on the right. On smaller ones, they are hidden by default and the user clicks on an icon to toggle the menu.