Fireship · @fireship

CSS Grid in 100 Seconds

Uploaded March 5, 2020 · Length 1:51

CSS Grid in 100 Seconds

Summary

learn css grid layout in 100 seconds, including grid template areas, tracks, and gap property.

  • css grid
  • css layout
  • grid template areas
  • css grid tutorial

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    CSS grin a system for laying out items

  2. 0:02

    across a movable set of horizontal and

  3. 0:05

    vertical lines inside a grid we have

  4. 0:07

    invisible lines that divide columns and

  5. 0:09

    rows the space between two parallel grid

  6. 0:11

    lines is known as a grid track and the

  7. 0:13

    space between four lines is known as a

  8. 0:15

    grid area in your HTML start with a

  9. 0:17

    parent element to serve as your grid

  10. 0:19

    container then all of its children will

  11. 0:21

    automatically become grid items let's

  12. 0:23

    imagine we wanted to build a website

  13. 0:24

    with a holy grail layout in the HTML if

  14. 0:27

    we have a container with five elements

  15. 0:29

    inside we'll start by setting the

  16. 0:30

    containers display property to grid now

  17. 0:32

    open your app in Firefox to visualize

  18. 0:34

    the gridlines tracks and areas it helps

  19. 0:37

    to imagine your website as an Excel

  20. 0:38

    spreadsheet in each individual cell add

  21. 0:40

    a label that represents the element that

  22. 0:42

    should appear there each cell in the

  23. 0:44

    grid represents one fractional unit in

  24. 0:46

    the middle we have an advertisement the

  25. 0:48

    main content and the sidebar then we

  26. 0:50

    have the top bar taking up three cells

  27. 0:51

    on the top and a footer on the bottom

  28. 0:53

    notice how this represents a three by

  29. 0:55

    three grid and we can use this as the

  30. 0:57

    value for the grid template areas

  31. 0:58

    property now we need to tell the

  32. 1:00

    children which grid area that they take

  33. 1:02

    up we can do that by providing the name

  34. 1:04

    to the grid area property that gives us

  35. 1:06

    the right layout but now we want to

  36. 1:07

    adjust the size of the rows and columns

  37. 1:09

    currently each column is taking up one

  38. 1:11

    third or one fractional unit of the

  39. 1:13

    available space we can change the width

  40. 1:15

    of the middle column by setting it to a

  41. 1:17

    fixed pixel value or change the ratio by

  42. 1:19

    giving it three fractional units

  43. 1:20

    likewise we can change the height of

  44. 1:23

    rows using the grid template rows

  45. 1:24

    property if we want to add spacing

  46. 1:26

    between our grid lines we can use the

  47. 1:28

    great gap property and we can Center the

  48. 1:30

    children vertically or horizontally

  49. 1:31

    using justify items or line items and

  50. 1:34

    make sure to check out the min Max and

  51. 1:36

    repeat functions to avoid duplication on

  52. 1:38

    larger grids this has been CSS grid and

  53. 1:40

    100 seconds stay tuned for a full grid

  54. 1:42

    project in a few days and make sure to

  55. 1:44

    hit the like button if you want to see

  56. 1:46

    more short videos like this thanks for

  57. 1:48

    watching and I will see you in the next

  58. 1:49

    one