Fireship · @fireship

CSS Card Tricks

Uploaded September 11, 2020 · Length 8:47

CSS Card Tricks

Summary

Learn how to create an animated card list using HTML and CSS, combining grid and flexbox layout, transforms, shadows, and transition animations.

  • css card tricks
  • html and css tutorial
  • grid and flexbox layout
  • css animations
  • css transitions
  • css shadows

Transcript preview

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

  1. 0:00

    i happened to be on css tricks the other

  2. 0:01

    day and when i saw this animated card

  3. 0:03

    list i thought

  4. 0:04

    wow that's a cool css trick so in

  5. 0:06

    today's beginner-friendly tutorial we're

  6. 0:08

    going to reverse engineer this ui

  7. 0:09

    element using nothing but html and css

  8. 0:12

    over the next few minutes you'll learn

  9. 0:13

    how to combine both grid and flexbox

  10. 0:15

    layout to position the cards

  11. 0:17

    we'll use transforms and shadows to make

  12. 0:19

    it look like the cards are stacked on

  13. 0:20

    top of each other we'll implement some

  14. 0:22

    transition animations and i'll throw in

  15. 0:23

    a few other tricks

  16. 0:24

    like a gradient text background and svg

  17. 0:27

    styles for this little semi-circle under

  18. 0:29

    the avatar if you're new here like and

  19. 0:30

    subscribe and you can find the full

  20. 0:32

    source code for this project on github

  21. 0:33

    and follow along with the write up on

  22. 0:35

    fireship io

  23. 0:36

    we're going to build this feature step

  24. 0:37

    by step from scratch so pull up your

  25. 0:39

    editor

  26. 0:39

    and create a file called card.css and

  27. 0:42

    index.html

  28. 0:44

    in your html type an exclamation point

  29. 0:46

    followed by tab

  30. 0:47

    to create the initial boilerplate then

  31. 0:49

    in the head of the document

  32. 0:50

    type in link to access the snippet for a

  33. 0:52

    css link and then point it to your

  34. 0:54

    card.css file and the body of the

  35. 0:56

    document we'll add a section this will

  36. 0:58

    be the main container for the card list

  37. 1:00

    then each individual card will be

  38. 1:01

    represented by an article element

  39. 1:03

    we'll add a header to each individual

  40. 1:05

    card and later in the video we'll come

  41. 1:07

    back and add an avatar

  42. 1:08

    and some tags now rather than target

  43. 1:10

    these elements directly i'm going to add

  44. 1:12

    a class name to each element then i'm

  45. 1:14

    going to copy and paste our markup so we

  46. 1:15

    have multiple cards to work with and

  47. 1:17

    just a friendly reminder

  48. 1:18

    it's much easier to copy and paste this

  49. 1:20

    markup from github

  50. 1:21

    now one quick thing i want to point out

  51. 1:23

    is that instead of a section article and

  52. 1:24

    header i could have just called

  53. 1:26

    all these elements divs this would work

  54. 1:27

    perfectly fine but when you write html

  55. 1:29

    you want to use semantic elements where

  56. 1:31

    you can or in other words use elements

  57. 1:33

    that clearly define what the content is

  58. 1:35

    all about

  59. 1:36

    in any case we can open up our html by

  60. 1:38

    right-clicking on the file and clicking

  61. 1:39

    copy path

  62. 1:40

    then we can paste that into the browser

  63. 1:42

    and you should get a result that looks

  64. 1:43

    like this

  65. 1:44

    and now we're ready to start

  66. 1:45

    implementing some css tricks at the top

  67. 1:48

    of the file i'm going to import a google

  68. 1:49

    font

  69. 1:50

    then i'll add some global styles to the

  70. 1:51

    body tag like a dark background and

  71. 1:54

    setting that font family as the default

  72. 1:55

    font

  73. 1:56

    and our ui is already looking much

  74. 1:58

    better currently the cards are flowing

  75. 1:59

    vertically but we want them to flow