Flexbox
- New value for the CSS
display
property - Used for aligning multiple elements along ONE axis
- There are two main parts: flexbox containers and flexbox items
- Getting Started with Flexbox video
Whenever you are adding display:flex
to an element you are really just talking about how to position the children elements of that element.
Flexbox Container Properties
display: flex
flex-direction
property can berow
,row-reverse
,column
,column-reverse
justify-content
property (along main axis) can beflex-start
,flex-end
,center
,space-around
,space-between
andspace-evenly
align-items
(on cross-axis) can beflex-start
,flex-end
,center
,stretch
,baseline
flex-wrap
can bewrap
,no-wrap
,wrap-reverse
Flexbox Item Properties
flex-basis
initial size for an itemflex-grow
controls the ratio for how items grow relative to each otherflex-shrink
controls the ratio of how items shrink relative to each otherflex
is a shorthand for flex-basis, flex-grow and flex-shrinkalign-self
to override container'salign-items
value for one itemorder
assign exact position of each item.
.container {
/* this is the flexbox container */
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-start;
}
.container .item {
/* these are the flexbox items */
flex-basis: auto;
flex-grow: 0;
/* these two will keep original content sizes */
flex-basis: 0;
flex-grow: 1;
/* these two will start the items at width 0 and then expand them equally */
flex-shrink: 1;
/* shrink them equally as the width of the container is reduced */
}
- Here is an excellent free online course for Flexbox.io
- Visual Guide to Flexbox Properties