A flex item is a child of a flex container. Give a parent `display: flex`, and its children become flex items automatically—no special declaration needed on each child. A flex container can arrange them in a row or column. section 12.1 section 12.2
Think of the container as setting the group rules. Its main axis runs in the direction of the items; its cross axis runs across that direction. Container properties can position the group along either axis and let items wrap onto additional lines. section 12.2
Then ask what each item needs to do:
- Fill spare room? Use `flex-grow`. It starts at `0`; positive values divide extra space among growing items. Values of `1`, `2`, and `1` split that space 25%, 50%, and 25%. section 12.4
- Running short on room? Use `flex-shrink`. Want to suggest a starting size? Use `flex-basis`. The `flex` shorthand can combine growth, shrinkage, and basis. section 12.4
- Need one item in a different position or alignment? Use `order` to change its order or `align-self` to override the container’s `align-items` setting. section 12.4
Center one item
Put an `h1` inside a `div`. Make the `div` a flex container, set both `justify-content` and `align-items` to `center`, and give it `height: 100vh`. The `h1` becomes the flex item and sits in the center of the browser window. No positioning gymnastics required. section 12.3
main {
display: flex; #1
flex-grow: 1; #2
}
article {
flex-grow: 3; #3
border: 1px solid black;
}
aside {
flex-grow: 1; #4
border: 1px solid black;
}
This CSS makes `main` a flex container for `article` and `aside`, while `main` itself grows as an item in the body container. The `article` and `aside` use growth values of `3` and `1` to share available horizontal space. section 12.6


