> For the complete documentation index, see [llms.txt](https://petercheng7788.gitbook.io/developer-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://petercheng7788.gitbook.io/developer-note/frontend/css/core/flexbox-and-grid.md).

# Flexbox & Grid

## Flexbox

### Flexbox Container

**Flex Wrap**

* If wrapped, the items can be moved into the next rows

**Align Items**

* Stretch will let the item height filled into container if it is a single row and height is not specified

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FXNSxJaMsf9Rye6AxKtci%2Fimage.png?alt=media&amp;token=480c4925-3926-449c-9e09-521bd65fc092" alt=""><figcaption></figcaption></figure>

**Justify Content**

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FAKh66g7LQnGKXVwFZGHS%2Fimage.png?alt=media&amp;token=6ca58737-a7e3-474c-849d-3c53ad42b541" alt=""><figcaption></figcaption></figure>

**Align Content**

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FdrIX9iU4NtuElrOxDx5b%2Fimage.png?alt=media&amp;token=ed9b2415-14cb-402d-a881-91dbd23291a9" alt=""><figcaption></figcaption></figure>

**Align Content vs Align Items**

* Align items focus on the items of a single row
* Align content focus on layout and distance of multiple rows

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2Fzl7SBMIBsq2FiSCvgWkR%2Fimage.png?alt=media&amp;token=e3d139c0-b7b2-4593-a97d-23f59106e2db" alt=""><figcaption></figcaption></figure>

### Flex Item

**Flex Grow**

* The ratio of width of item in a single row,  but easy to be affected by width / flex-basis , here is an example below

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FBubnXkZpj1S1kVHR6jpC%2Fimage.png?alt=media&amp;token=536d91f3-0013-487c-b632-d07f06a7f999" alt=""><figcaption></figcaption></figure>

**Width / Flex-basis**

* The minimum width of item

**Flex**

* The `flex` property is a shorthand property for the `flex-grow`, `flex-shrink`, and `flex-basis` properties.
* `flex: 1 1 200px => growth ratio 1, shrink ratio 1, minimum width/ height 200px`

**Align Self**

* It is used override the align item of container

## Grid

### Grid Container

**grid-template-columns**

* To describe the ratio of column

```css
// ratio of columns: 1 : 2 : 1
grid-template-columns: 1fr 2fr 1fr;
// all the ratio of columns are the same
grid-template-columns: auto auto auto;
```

**justify-content**

* Focus on the the postition of layout

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FjaQHnfAis0tfIKfznPay%2Fimage.png?alt=media&amp;token=b88614bc-690a-4c9d-855e-5ec37fb267a0" alt=""><figcaption></figcaption></figure>

**Align content**

* Same as justify-content, but with different axis

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FvUPjSC7C5Hj0DfyGwj2i%2Fimage.png?alt=media&amp;token=7ed9e156-a5a0-4dfc-8f0c-55035a1cf503" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FKsEqYWdIr2z897h0WJUf%2Fimage.png?alt=media&amp;token=bd22df45-2cf5-438d-a7fe-b496dd235172" alt=""><figcaption></figcaption></figure>

**Align items**

* focus on the position of grid item

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FBT3kJmUsxlkZXWPMHAcv%2Fimage.png?alt=media&amp;token=f39f1e58-327f-4786-a144-124da39d92df" alt=""><figcaption></figcaption></figure>

**Justify item**

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FR3A2pZxQCyalTyBAqODO%2Fimage.png?alt=media&amp;token=55af6df7-a869-47b4-97c6-27ba2c5c09db" alt=""><figcaption></figcaption></figure>

### Grid Item

**Grid Column & Grid Row**

* To define where the item will start, and where the item will end.

```css
// start on column 1 , end before column 5
grid-column: 1 / 5;

// start on row 1, end before row 5
grid-row: 1 / 5;
```

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2F2qhwl5r7Zq3J5rrrmETO%2Fimage.png?alt=media&amp;token=4c53349b-5284-4c66-b653-2fae58ad196c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2Fgbo5xAREsMymWcrC3dm0%2Fimage.png?alt=media&amp;token=b9ed724e-4847-442b-9c39-0e81ab2def86" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FebTt0TdYkrHveMHb0oem%2Fimage.png?alt=media&amp;token=faa0f2e5-2d90-44e7-9fee-5ca15475be69" alt=""><figcaption></figcaption></figure>

* If grid-row and grid-col is overlap, the element will be overrided

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FYA76I3qg6eRfqAOK8oyw%2Fimage.png?alt=media&amp;token=abc72894-449e-4323-963b-3493eb6e3bca" alt=""><figcaption></figcaption></figure>

**Grid Area**

* It can be used assign a name , used to represent the layout

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2F97tTmOJziQANojY6H3JS%2Fimage.png?alt=media&amp;token=dc590972-ce97-426f-85fe-1f5becb44f8e" alt=""><figcaption></figcaption></figure>
