Fireship · @fireship

CSS Pseudo-classes: in 100 Seconds

Uploaded June 8, 2020 · Length 2:00

CSS Pseudo-classes: in 100 Seconds

Summary

css pseudo-classes explained for styling element states in 100 seconds

  • css pseudo-classes
  • css hover
  • css focus
  • css selectors
  • css styling

Transcript preview

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

  1. 0:00

    pseudo-class a way to style an element

  2. 0:02

    based on a change to its state for

  3. 0:04

    example when you hover over a button in

  4. 0:06

    the browser it automatically adds this

  5. 0:08

    hover keyword to the selector when

  6. 0:10

    working with pseudo classes it can be

  7. 0:11

    useful to go into the browser inspector

  8. 0:13

    and force the state on the element

  9. 0:14

    you're targeting there are a bunch of

  10. 0:16

    different pseudo classes out there like

  11. 0:17

    focus when the user is actively using a

  12. 0:19

    form input or disabled when a button has

  13. 0:21

    the disabled attribute set to true

  14. 0:23

    pseudo classes are also useful when

  15. 0:25

    working with a collection of elements we

  16. 0:27

    can easily target the first or last

  17. 0:29

    element in the list relative to its

  18. 0:30

    other siblings at this level by

  19. 0:32

    targeting in the first child or last

  20. 0:34

    child pseudo classes if we want to be

  21. 0:36

    more specific we can use last of type so

  22. 0:38

    it only targets this type of element but

  23. 0:40

    what if we want the second third or

  24. 0:41

    fourth element in that case we can use

  25. 0:43

    nth child and pass an argument for the

  26. 0:45

    element that we want to grab or instead

  27. 0:47

    of a specific number we might want to

  28. 0:49

    use odd or even or maybe we want to grab

  29. 0:51

    every fifth element in the list multiply

  30. 0:53

    5 by n to get every 5th element like 5

  31. 0:56

    10 15 and so on you can also use

  32. 0:58

    addition and subtraction here to create

  33. 1:00

    any kind of pattern you want now

  34. 1:01

    sometimes you might select something in

  35. 1:03

    your CSS but what you actually want to

  36. 1:05

    style is everything else for that we

  37. 1:07

    have the non pseudo class which performs

  38. 1:09

    negation notice how when we hover over

  39. 1:11

    an element in this list all the other

  40. 1:13

    elements are styled but not the actual

  41. 1:14

    element that we're hovering over that's

  42. 1:16

    because we're targeting all the elements

  43. 1:18

    that are not hovered pseudo selectors

  44. 1:19

    are especially powerful when working

  45. 1:21

    with forms one of my favorites is focus

  46. 1:23

    within which allows a parent element to

  47. 1:25

    see if one of its children has focus and

  48. 1:27

    that's especially useful if you have

  49. 1:29

    something like a drop-down menu and once

  50. 1:31

    you keep it open after the user has

  51. 1:32

    clicked a button if you're building a

  52. 1:34

    web app with an international audience

  53. 1:35

    you might want to know about fileting

  54. 1:36

    selector use it to apply custom styles

  55. 1:39

    to any element that has a Lang attribute

  56. 1:40

    you can use it to make all of your Dutch

  57. 1:42

    text orange or combine it with int child

  58. 1:44

    to make your German text black red and

  59. 1:46

    yellow this has been pseudo classes and

  60. 1:48

    100 seconds hit the like button if you

  61. 1:50

    want to see more short videos like this

  62. 1:52

    thanks for watching and I will see you

  63. 1:54

    in the next one