Target Custom HTML Element Patterns with DOM Hierarchy Pseudo Classes in CSS

Share this video with your friends

Send Tweet

DOM hierarchy pseudo-classes allow you to style specific elements based on where they fall in the hierarchy and what type of elements they are. You can also use :nth-child to target custom element patterns, like every other element (odd or even).

NadGu
~ 5 years ago

Very useful lesson but the -n + 4 confuses me. The -n indicates that the element 0 is included in the selection? But how is it possible if the 0th element doesn't exist?

Garth Braithwaiteinstructor
~ 5 years ago

If it targets an element that doesn't exist, it is just skipped over - that's how all CSS selectors work. If you have a selector that targets an element that doesn't exist, no warnings or errors are thrown, it is just ignored.