Flexbox Button Quickie

Patrick Tunga-Lergo
3 min readApr 23, 2017

--

Developing my portfolio site I needed a button that would behave predictably across all platforms.

So I made one using the flexbox layout. Here’s how and why I did it.

A Flexbox container modifies the width or height of its children(items) to fill space across the main and cross axis (x, and y axis). In the case of my button it is treated as an ‘item’.

flexbox axis chart from MDN

I ultimately set my button to predictably align itself in the middle of any container axis which saves me time from adjusting floats or margins across media queries for different screen sizes.

flexbox button codepen

What i’m left with is a simple button that I can easily drop into any projects without much tinkering to the existing css besides changing the button’s container attributes display to flex and align items to center.

Button Style

Raising buttons add dimension. For UX it’s important to make buttons look and behave like buttons.

add dimension by raising your button

Some neat tricks I used involve text-rendering, and font-smoothing to make the button look very crisp and sharp.

Sharpen the button’s appearance

I also used scale transform instead of a zoom so I can slow down the button’s transition speed to correlate with the box-shadow’s transition speed for the hover animation.

button hover effect

Conclusion

Flexbox is a great way to make complex layouts that behave predictably. In my scenario I used it for a simple button but there’s plenty of other ways flexbox will come in handy and I recommend learning how to use it. Below are some great starting points in understanding flexbox.

--

--

Patrick Tunga-Lergo

Lead Product Designer ( Design Systems) for ADT | Co-Founder of dotHello Web Solutions | Editor-In-Chief of 8Pounds Music | Stomper of sand castles