what is CSS flexbox?๐ค
The flexible box module, usually refer as flexbox, helps us to design a responsive website, Before the flexbox layout module there were four layout modes:
- Block
used for sections in a webpage
- Inline
used for text
- Table
used for two-dimension table data
- Positioned
used for explicit position of an element
Main Axis
The main axis direction is defined by flex-direction, the default direction is left to right
Flexbox Elements
To start using the flexbox model, we first need to define a flex container.
<div class="container"> <div>1</div> <div>2</div> <div>3</div> </div>
Flexbox Properties
๐ display
the flex container become flexible by setting the display property to
flex
.container{ display: flex; }
output:-
flex-direction property
the flex-direction defines the direction of the container
๐ column
.container { display: flex; flex-direction: column; }
output:-
๐ column-reverse
column-reverse
value stacks the flex items in vertical direction meaning from bottom to to.
.container { display: flex; flex-direction: column-reverse; }
output:-
๐ row
the
row
value of flex-directon stacks the flex items horizontally ( from left to write )
.container { display: flex; flex-direction: row; }
output:-
๐ row-reverse
the
row-reverse
stacks the flex item from right to left
.container { display: flex; flex-direction: row-reverse; }
output:-
flex-wrap property
flex-wrap
property specify the flex item should wrap or not๐ wrap
.container { display: flex; flex-wrap: wrap; }
output:-
๐ nowrap
.container { display: flex; flex-wrap: nowrap; }
output:-
๐ wrap-reverse
.container { display: flex; flex-wrap: wrap-reverse; }
output:-
flex-flow property
.container { display: flex; flex-flow: row wrap; }
output:-
justify-content property
๐ center
.container { display: flex; justify-content: center; }
output:-
๐ flex-start
.container { display: flex; justify-content: flex-start; }
output:-
๐ flex-end
.container { display: flex; justify-content: flex-end; }
output:-
๐ space-around
.container { display: flex; justify-content: space-around; }
output:-
๐ space-between
.container { display: flex; justify-content: space-between; }
output:-
align-items property
๐ center
.container { display: flex; align-items: center; }
output:-
๐ flex-start
.container { display: flex; align-items: flex-start; }
output:-
๐ flex-end
.container { display: flex; align-items: flex-end; }
output:-
๐ stretch
.container { display: flex; align-items: stretch; }
output:-
๐ baseline
.container { display: flex; align-items: baseline; }
output:-
align-content property
๐ center
.container { display: flex; align-content: center; }
output:-
๐ flex-start
.container { display: flex; align-items: flex-start; }
output:-
๐ flex-end
.container { display: flex; align-items: flex-end; }
output:-
๐ stretch
.container { display: flex; align-items: stretch; }
output:-
๐ space-around
.container { display: flex; align-items: space-around; }
output:-
๐ space-between
.container { display: flex; align-items: space-between; }
output:-
๐ Perfect Centering
.container { display: flex; justify-content: center; align-items: center; }
output:-