Fireship · @fireship
CSS Pseudo-classes: in 100 Seconds
Uploaded June 8, 2020 · Length 2:00
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.
- 0:00
pseudo-class a way to style an element
- 0:02
based on a change to its state for
- 0:04
example when you hover over a button in
- 0:06
the browser it automatically adds this
- 0:08
hover keyword to the selector when
- 0:10
working with pseudo classes it can be
- 0:11
useful to go into the browser inspector
- 0:13
and force the state on the element
- 0:14
you're targeting there are a bunch of
- 0:16
different pseudo classes out there like
- 0:17
focus when the user is actively using a
- 0:19
form input or disabled when a button has
- 0:21
the disabled attribute set to true
- 0:23
pseudo classes are also useful when
- 0:25
working with a collection of elements we
- 0:27
can easily target the first or last
- 0:29
element in the list relative to its
- 0:30
other siblings at this level by
- 0:32
targeting in the first child or last
- 0:34
child pseudo classes if we want to be
- 0:36
more specific we can use last of type so
- 0:38
it only targets this type of element but
- 0:40
what if we want the second third or
- 0:41
fourth element in that case we can use
- 0:43
nth child and pass an argument for the
- 0:45
element that we want to grab or instead
- 0:47
of a specific number we might want to
- 0:49
use odd or even or maybe we want to grab
- 0:51
every fifth element in the list multiply
- 0:53
5 by n to get every 5th element like 5
- 0:56
10 15 and so on you can also use
- 0:58
addition and subtraction here to create
- 1:00
any kind of pattern you want now
- 1:01
sometimes you might select something in
- 1:03
your CSS but what you actually want to
- 1:05
style is everything else for that we
- 1:07
have the non pseudo class which performs
- 1:09
negation notice how when we hover over
- 1:11
an element in this list all the other
- 1:13
elements are styled but not the actual
- 1:14
element that we're hovering over that's
- 1:16
because we're targeting all the elements
- 1:18
that are not hovered pseudo selectors
- 1:19
are especially powerful when working
- 1:21
with forms one of my favorites is focus
- 1:23
within which allows a parent element to
- 1:25
see if one of its children has focus and
- 1:27
that's especially useful if you have
- 1:29
something like a drop-down menu and once
- 1:31
you keep it open after the user has
- 1:32
clicked a button if you're building a
- 1:34
web app with an international audience
- 1:35
you might want to know about fileting
- 1:36
selector use it to apply custom styles
- 1:39
to any element that has a Lang attribute
- 1:40
you can use it to make all of your Dutch
- 1:42
text orange or combine it with int child
- 1:44
to make your German text black red and
- 1:46
yellow this has been pseudo classes and
- 1:48
100 seconds hit the like button if you
- 1:50
want to see more short videos like this
- 1:52
thanks for watching and I will see you
- 1:54
in the next one


