Sitemap
Brett Schules

Brett Schules

CSS 3 Flexbox

3 min readNov 9, 2017

Can you imagine a world without CSS? Sure, we would still have functioning Web Applications that can complete their tasks, however they would just a skeleton of boring black and white web pages with words. This is where CSS or Cascading Style Sheets comes in to create layouts for web pages to create a more memorial experience for it’s users. In today’s world where a website can be view either on a desktop computer, smartphones, or tables; CSS 3 is a very powerful tool that allows us to adapt to user demands. The CSS 3 flexbox allows us to create web pages that are responsive to various devices. Let’s check it out!

Get Brett Schules’s stories in your inbox

Join Medium for free to get updates from this writer.

In order to create a flexbox, we first need to give our class “container” the flex property so that it will enable the flex content for it’s child elements.

.container {
display: flex;
}

Then, we can give it a property. For example, the flex-direction property allows you to specify the direction you want you child elements to be displayed in. The row value allows you to align your elements in ascending order that the child elements are created horizontally. Row-reverse aligns the elements in descending order. Column and column-reverse does the same thing as row and row-reverse except vertically.

.container {
display: flex;
flex-direction: row | row-reverse | column | column-reverse;
}
Note: The flex-direction property take in one value at a time. The | is just to show multiple examples.
The layouts are in the following order row, row-reverse, column, column-reverse.

The justify-content property allows us to dictate how we want to place our elements on a webpage so they are spaced out evenly. Again, this allows our page to be responsive ensuring that it adjusts accordingly to the different screen sizes.

.container {   
justify-content: flex-start | flex-end | center | space-between |
space-around | space-evenly;
}

Flex-start: elements are arranged toward the start line. Flex-end: elements are arrange toward to end line. Center: elements are centered along the line. Space-between: the first element is arranged to the start line, second element to the center, and third to the end line. Elements are evenly spaced in the line to take up the width of the page. Space-around: elements are evenly distributed in the line with equal space around them. Space-evenly: elements are distributed so that the spacing between any two items as well as the space from the start and end lines.

With the align-content property we can do the same things as the justify-content but vertically.

There are many more useful properties that comes with the flex-box. Since it is almost midnight, I am not going to list them here and bore you even more. Rather check out this interactive fun game that allows you to play a game while you learn the CSS 3 flex box! http://flexboxfroggy.com/. Also, a big thanks to Chris Coyier and his website for the graphics displaying the flex-box used in this blog. https://css-tricks.com/snippets/css/a-guide-to-flexbox/

--

--