From the course: CSS: Selectors
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Understanding only selectors, :only-child, :only-of-type - CSS Tutorial
From the course: CSS: Selectors
Understanding only selectors, :only-child, :only-of-type
- [Instructor] The next topic is the only selectors, including only child and only of type. Let's talk about the easy one first. That is the only child selector. Just like in real life, an only child is one without siblings of that particular type. So let's go ahead and take a look at an example of this. We have here in line number eight, we have a strong tag here that's all by itself. It is an only child. Also, if you take a look here in line six, this strong tag at the end of the sentence is an only child also. It is a child of the M tag which is surrounding that. So if we go ahead and write a strong colon only child, we wind up getting both of those things selected. That's the definition of an only child. There it is. Only of type is a little bit different. So that indicates that there may be several siblings, but there's only one of this particular type. So an example of that is here in the aside, the aside actually has two children, it has an H2 and it has a paragraph. But the H2…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Understanding only selectors, :only-child, :only-of-type2m 22s
-
(Locked)
Understanding first and last selectors, :first-child, :first-of-type, :last-child, :last-of-type3m 7s
-
(Locked)
Understanding nth selectors – :nth-child, :nth-of-type, :nth-last-child, :nth-last-of-type4m 9s
-
(Locked)
:root and :empty4m 27s
-
(Locked)
-
-
-
-
-