Introduction to Flex in Web Development: Vuetify Edition
Tags: beginners, webdev, vuetify, flexbox
Published: 2020-05-11 19:00:14

Flexbox may not be a new web development concept, yet it still remains one of the fundamental concepts developers use to craft user interfaces in 2020.
Things web developers must always keep in mind include:
* Responsive design
* Having a proper layout

To succeed, our biggest weapon is flexbox, as well as general grid concepts.

This tutorial will cover what flexbox is, the most used properties, and will conclude with a part of how Vuetify works with flexbox.

##What is Flexbox?

The flexbox layout aims to provide a way to lay out, align and distribute space among items in a container, even when their size is unknown and/or dynamic.

Before going further, we should understand the difference between a parent and a child element in webdev. It’s a basic concept which has a high impact when we start using flexbox.

![parent-children](https://dev-to-uploads.s3.amazonaws.com/i/t7nrh15jhtmhl837ek70.png)

Flexbox is not a single property -  it’s a whole module which involves a lot of things.

It includes properties for the parent element, known as a `flex container` and for the children element known as a `flex item`.

The main idea behind the flex layout is to give the container the ability to alter its items’ width/height (and order) to best fill the available space (mostly to accommodate to all kind of display devices and screen sizes).

A flex container expands items to fill available free space or shrinks them to prevent overflow.

Next, we will look into the basics about flex and the most used properties with some examples

Let’s see behind some flexbox properties and their utilities.

In my opinion, the best way to learn things is to play with them.
[Flexbox playground](https://flexbox.netlify.app/) is perfect for that! The code used to create this app is the same as you can find in the Vuetify Docs.

If you prefer textual explanation, you should have a look to [CSS Tricks Flexbox guide](https://css-tricks.com/snippets/css/a-guide-to-flexbox/#flexbox-background)

## How does Vuetify work with flexbox? 

When it comes to using Vuetify, this UI framework makes it so that you do not need to to write css flex class inside your web application. This is because Vuetify  has two different ways to handle flex design.

The first one is using `flex-helpers`, as you can find [here](https://vuetifyjs.com/en/styles/flex/#flex). It covers the basics flex properties.

The second way is to use v-row (as a flex-container) and v-col (as a flex-item).
This example is from the official Vuetify documentation:

```javascript
    <v-container>
      <v-row>
       <v-col>
         <v-card
           class="pa-2"
           outlined
           tile
         >
           One of three columns
         </v-card>
       </v-col>
       <v-col>
         <v-card
           class="pa-2"
           outlined
           tile
         >
           One of three columns
         </v-card>
       </v-col>
       <v-col>
         <v-card
           class="pa-2"
           outlined
           tile
         >
           One of three columns
         </v-card>
       </v-col> 
     </v-row>
   </v-container>
```

`v-row` is a wrapper component for `v-col`. It utilizes flex properties to control the layout and flow of its inner columns. It uses a standard gutter of 24px. This can be reduced with the `dense` prop or removed completely with `no-gutters`.


* v-col is a content holder that must be a direct child of v-row


* v-row and v-col contain different props to interact with align, justify and order, offset.

* You can find more information [here](https://vuetifyjs.com/en/components/grids/#api)



Now let’s play some games to understand all the basics!

You can practice your flexbox skills on the two websites listed below:
* [Flexbox froggy](https://flexboxfroggy.com/)
* [Flexbox defense](http://www.flexboxdefense.com/)

Thanks for reading this introduction post on flexbox! Stay tuned for more posts with detailed examples on this concept in the near future.

Sources: 
* https://flexbox.netlify.app/ 
* https://css-tricks.com/snippets/css/a-guide-to-flexbox/#flexbox-background
* https://flexboxfroggy.com/
* http://www.flexboxdefense.com/

***
This blog post is a part of [Vuetify Beginner's Guide Series](https://vuetifyjs.com/en/introduction/guide/). 🐣 Each blog has been collaboratively worked on by the Vuetify Core Team. Interested in contributing a topic? ➡ Reach out to [Johanna](https://dev.to/johannarlee) on Dev.to or in the [Vuetify Community Discord](https://discord.com/invite/s93b7Fv).