Flex Box in CSS
Tags: css, webdev
Published: 2021-08-31 16:26:37

Flex box is used in CSS for layout of items in the html page in responsive manner. We have other layout properties like inline, block and inline-block, through which can be achieved responsiveness, centering items or assigning same available width or height to items using margins, paddings or float, writing css for different screen size which becomes very complicated when page has more items in it. In this case it is better to use flex-model layout.

As we know flex-box is layout related CSS property which contains certain properties which help us to
use flex-box more effectively. They are

**flex-direction:**
flex-direction is used for showing items in container horizontally or vertically aligned.for that we use below css code:
```
.container {
  display: flex;
  flex-direction: row;
}
```
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7z7gluzgqz4bywys4ict.png)
```
.container {
  display: flex;
  flex-direction: column;
}
```
 ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm62f2wpxrgpgh9y8dtx.png)

use column-reverse or row-reverse as flow-direction it works same as column and row respectively but orders are reversed.  


**flex-wrap:**

flex-wrap property use for whether items of container will use free space of container.for that 
flex-wrap has two properies wrap and no-wrap.
no-wrap tries to align item in one line where as no-wrap if width is greater than screen size it will add that item to next line.
```
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: no-wrap;
}
```
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3t6cikaqf9sz6j5gh30.png)

```
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/knj69x8imr5swpkwipqu.png)

  
**flex-flow:**

flex-flow is property to set flex-direction and flex-wrap in same property like 

```
.container {
  display: flex;
  flex-flow: column no-wrap | column wrap;
}
```
```
.container {
  display: flex;
  flex-flow: row no-wrap | row wrap;
}
```

**justify-content:**

Justify-content property is used to set alignment of items in box on same-axis 

```
.container {
  display: flex;
  justify-content: flex-start | flex-end | center | space-between | space-around;
}
```
center: 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4ff7hwhhudt56qh1sy6.png)

flex-start:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azi126ptquc8q0y3npzg.png)

flex-end:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmshv6me79q6zqabk0bk.png)

space-around:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdo2hw0bpm4q5acdt54w.png)

space-evenly:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wyauzvtffmn9cv86qv9.png)


**align-items:**
this property aligns item on other axis of flex-box container. If flex-direction is set column then this property is used to align items on x axis and vice-versa.
```
.container {
  display: flex;
  justify-content: flex-start | flex-end | center;
}
```

center:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b8gok3yob59huzyr2ih.png)

flex-start:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eio4elxzhz9i88fjr36s.png)

flex-end:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c7awi47zu0pr5taqjzv.png)

This is basic level of flex-box understanding. There are other properties of flex-box like flex-grow, flex-shrink, align-self on that you can read about it. Thanks for reading this blog.
Thanks for reading the blog.