Flexbox by Wes Bos
- Works on containers.
flex-direction : row; /* Default, wherein the main axis goes from left to right, cross axis from top to bottom. */
flex-direction : column; /* Main axis goes from top to bottom. */
flex-direction : row-reverse;
flex-direction : column-reverse;
- Works on containers.
flex-wrap: wrap;
- Works on flex items
- Default order on flex items is 0.
- A higher order takes the item to right.
- A lower order takes the item to left.
- Negative values of order are legit.
order: SOMENUMERICALVALUE;
- Works on containers
justify-content: flex-start; /*default*/
justify-content: flex-end;
justify-content: center;
justify-content: space-between;
justify-content: space-around;
min-height: 100vh; /*Givin it height > contents is necessary else the container will end as soon as items are enclosed.*/
flex-direction: column; /*change main axis from top to bottom*/
justify-content: center; /*now the divs are aligned vertically in the center*/
- Works on containers
- Works on cross axis(!important point to notice) cos align-items:center wont work on main axis.
align-items: stretch; /*default*/
align-items: center; /*this aligns the item across the cross axis, not the main axis, so give container some height*/
height: 100vh; /*Without height it wont be able to center across the cross axis.*/
align-items: flex-end;
align-items: baseline; /*will align to the base of the text in each box*/
- Works on containers
- Works only on cross axis
- Removes previously defined heights on boxes
- needs wrap
flex-wrap: wrap; /*align content requires wrap around to work*/
align-content: stretch; /*default*/
align-content: flex-start;
align-content: flex-end;
align-content: space-between;
align-content: space-around;
align-content: center;
- Works on flex items.
- Wors on cross axis
- Removes previously defind heights on items
.box1 {
align-self: stretch;
align-self: flex-start;
align-self: center;
align-self: flex-end;
}
- Works on flex-items
- Works on main axis
.box{
flex: 1; /* will make all boxes with class box of equal size and stretch full horizontally */
}
.box2 {
flex: 2 /* Make box2 double the size */
}