What is CSS flax Box?

In this article. I’m telling you full basic Information about the flexBox.

Rajdeep Singh
Rajdeep Singh

4 min read

Table of contents

Flexbox is to give the container the ability to expand and Shrink elements base on the available space. Flexbox Layout replaces float Layout Design New way to build one-Dimensional layouts.Flexbox prefix when writing CSS code.

display:flex;
copy success
Flexbox Working Example

let start it

flexbox properties:

  1. Flex-direction
  2. flex-wrap
  3. flex-flow
  4. flex-grow
  5. flex-shrink
  6. flex-basis
  7. flex
  8. justify-content
  9. align-content
  10. align-item
  11. order

1.flex-direction

Flex direction

Is use flex-direction on the website on flex-direction provides direction row or column-wise.

Properties value:

Note: Do Not work with inner item

.flex-container {
display: flex;
flex-direction: column;
/* flex-direction: row; */
}
copy success

2. flex-wrap

Flex Warp

some over content overflow in that condition use flex-wrap

flex-warp property value:

.flex-container {
display: flex;
flex-wrap: wrap;
}
copy success

3.flex-flow

The flex-flow shorthand of the flex-direction and flex-wrap.when using in CSS file:first, use flex-direction after use flex-wrap.Syntax:

flex-flow: flex-direction flex-wrap;
copy success
.flex-container {
display: flex;
flex-flow: row wrap;
}
copy success

4. flex-grow

flex grow

Flex-grow work on the child item, not a parent item. Flex-grow gives equal space and also works on weight.

syntax:

flex-grow:1;
copy success

The flex-grow gives value base on a number like 1,2,3….n.

<div class=”flex-container”>
<div>1</div>
<div>2</div>
<div style=”flex-grow: 2">3</div>
<div>2</div>
</div>
copy success

5. flex-shrink

flex-shrink use to create a responsive web layout.

flex-shrink:0;
copy success

No work. But when increase value to zero. Then web layout shrink.

<div class=”flex-container”>
<div>1</div>
<div>2</div>
<div style=”flex-shrink: 0">3</div>
<div>4</div>
<div>5</div>
</div>
copy success

6. flex-basis

The flex-basic work like max-width.but in max-width fix width size.the flex-basic work with width and space. Note: flex-basis use to the individual item.

<div class=”flex-container”>
<div>1</div>
<div>2</div>
<div style=”flex-basis: 200px”>3</div>
<div>4</div>
</div>
copy success

7. flex

The flex property is a shorthand property for the flex-grow, flex-shrink, and flex-basis properties.

.item {
display: flex;
flex: 1 1 150px;
}
copy success

8. justify-content

justify content inside CSS

Justify-content properties use for Horizontal Alignment

property value:

.flex-container {
display: flex;
justify-content: center;
/* Write all value */
}
copy success

9. align-content:

align-content to use align item to vertical. Some time use height and width on the item in that condition data is overflow.

.flex-container {
display: flex;
align-content: space-between;
}
copy success

10. align-items

align-items

Align-self use to the individual item. Align-self align item to vertical item.

.flex-container {
display: flex;
height: 200px;
align-items: center;
}
copy success

11. order:

order in flexbox

When using the order property in the flex-box. Use to order change the item order according to your requirement.

order: number;
copy success
<div class=”flex-container”>
<div>1</div>
<div style=”order: 5">2</div>
<div>3</div>
<div>4</div>
<div style=”order: 2">5</div>
</div>
copy success

use margin property enhances your work.