Better Programming

Advice for programmers.

Follow publication

Member-only story

How To Create Responsive Tables With Flexbox and React

Gerard van der Put
Better Programming
Published in
6 min readMar 18, 2021

Example of responsive tables
What we will create today! Photo by the author.

Popular frameworks like Bootstrap and Semantic UI all have components that you can use to create responsive tables or grids. But there are downsides to using those solutions. First of all, they’ll force you into using these frameworks — or at least parts of them — in your applications, with all the overhead that’s caused by that.

Even more importantly, it’s not always easy to customize the behavior of those out-of-the-box components.

Today, I’ll show you that it’s not hard to create responsive tables from scratch. With a bit of CSS (Flexbox), some media queries, and a handful of very simple React components, you can create any table you want, and it will change shape on every breakpoint in the way you want. You’ll have full control.

On top of that, it will be a great exercise.

And with a lot of animated GIFs, there is little that’s stopping you from reading on. Enjoy!

Animation showing what will be created
Animation: We’ll explain every detail of creating this example.

Flexbox Basics

Creating a single row with some cells (some people prefer to call them columns, but I’ll stick with cells throughout this article) is quite straightforward.

In the image above, you see a row (a DIV element) containing four cells. The row is a Flex container:

display: flex;
flex-direction: row;

And we have defined two types of cells:

  • Growing cells (A and C)
  • Fixed-width cells (B and D)

The fixed-width cells have a width of 100 pixels, and this never changes. The growing cells are Flex items. Together, they take up all the available width, and without specifying otherwise, they’ll divide this available width equally.

The relevant styling:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Gerard van der Put
Gerard van der Put

Written by Gerard van der Put

Lead developer for a large industry-leading tech company. Support me! https://gerardvanderput.medium.com/membership.

Responses (1)

Write a response