Flex And Grid Layout, Project Part II

Before we continue with our project, we should know a bit about Flex.

Flex stands for Flexible Box Layout. In flex we arrange elements relative to each other either horizontally or vertically. The best example of flex is youtube.

Though we can arrange them without using flex as well, but flex helps to arrange these elements smoothly in a better way and with lesser code.

Flex Direction

The default direction of flex is Horizontal(row).

So as to understand this let’s create a bigger div and 4 smaller div inside that parent div and give them some colors.

In order to change flex direction, we can change that using property flex-direction: column.

If we want to place the child div from right to left, then we can use the property value as row-reverse.

Question: What if we want to place the div’s in below order Div2, Div3, Div1, Div4, means in the order we want ?

For that we can set the property order to the child div explicitly. By default the order value is 0.

If order for 2 or more div is same, then element would be based on the html code

Flex Wrap

We have setup H&W of child div to 200 and 200

Let’s try to add one more div and see what happens

Though the height and width was set to 200px, 200px. On adding a new div, the width has reduced and div’s have adjusted themselves.

If we want the div’s should be displayed as per the height defined, then we need to use flex-wrap property.

Default value of flex-wrap property is no-wrap.

Flex Grow And Flex Shrink

Let’s make some change in the html and css code. Just keeping 2 div and reducing the value of the parent div so as to understand this concept.

As the child div as 200px,200px and the parent div is 500px. There is a remaining of 100px available.

If we want that the child div should adjust accordingly to occupy the whole parent div, then we can use the property flex-grow.

The value means that div1 will grow by 80% of 100px i.e 80px and div2 will grow by 20px

Now so as to understand the concept of flex-shrink, let’s reduce the width to 300px from parent div

By default the div’s will distribute equally. Let’s implement flex-shrink property where we will deduct 80% from the div1.

Flex Justify Content

Let’s just directly jump into the practical

This is the default value
justify-content:flex-end;
justify-content: center
justify-content: space-around
justify-content: space-between

Align Content

It is used to align the elements across the cross axis. For example

Let’s understand this with help of an example.

flex-direction: row;
    align-items: flex-start;
flex-direction: row;
    align-items: flex-end;
flex-direction: row;
    align-items: center;
Stretch respects the height defined for the inner div. SO changed height to auto

flex-direction: row;
align-items: stretch;
#container div{    
height: auto;    
width: 100px;}

We can set max/min height as well.

Let’s see the last one which is baseline. Let’s include margin so as to understand this.

Without baseline
With baseline

Project

Converting Resume Code to Flex

Skills, education, portfolio, contact section would be in a form of flex. Let’s make that change.

So as to see the sections with different color let’s set height as 75vh and later we can change that.

Skills Section

Let’s create html for this first.

created a class section-heading, as all sections would have almost same property

Let’s jump onto the css part of the above code

Now let’s display the skills in form of a bar %. Let’s create a HTML for the same.

Let’s align the div in center.

Let’s modify our skills display section as per our need.

This is the css for the multiple skills tab

Let’s create the skills tab now

In this we will have a parent div with color grey and a child div with some other color which will indicate the percent of that particular skill.

Here is the HTML code for one skill

Now let’s write relevant CSS code for this skill

Similarly we will add the remaining of the skills.

250px answer

About the author

Deepak Sood

Deepak Sood is Lead Consultant in an IT firm holding expertise in Devops and QA Architecture with 8 years of experience.

His expertise is in building highly scalable frameworks. His skills include Java, Configuration Management, Containers, and Kubernetes.

Reach out to him using contact form.

View all posts