02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Travelling through a document with CSS rules

In the last few lectures we were introduced to a global flat and simple rules. In this lecture, we will learn how to travel through the HTML document and define more specific rules by combining everything we learnt so far.

Video Transcript

00:00Over the last three lectures, we were introduced to the three major ways to control CSS.
00:06We said directly manipulating an element by saying div or paragraph.
00:10We said a class, which is something we control and we create as we've seen.
00:14Or an ID, which is something specific to a specific item.
00:18An ID, by the way, doesn't really have a traveling path.
00:21You could just go directly to that ID very easily.
00:24Same is true with a class.
00:26But what happens if you want to travel through and you want to only, for example,
00:30items that are inside of paragraphs that have a class of mmm.
00:35And that's exactly going to be the topic of this lecture.
00:38We're going to take a look at traveling through an HTML document using CSS rules.
00:43Let's jump right into it and see it in action.
00:46We traveled through elements before, but I want to take a look at the traveling
00:51now that we've added in also classes and IDs.
00:55I wanted to take a deep look into, for example, how do we refer to a specific item
01:01on the stage and how we could play around with the different rules.
01:05Now, if we wanted to, for example, refer to all the H1s that are sitting inside
01:10of the specific question, what I could have done is gone to my H1
01:14instead of setting my div. What if there are other divs?
01:18Instead of that, I could say, hey, if you're inside of a question,
01:21then your H1 will be equal to a specific value.
01:25And I'm going to go ahead and just delete that extra one.
01:28All right, so you can see how I could use those into the traveling rules.
01:32Not only I could use it into the traveling rules,
01:35I could set also specific inline rules.
01:38So, for example, what if I want this 30 only to happen to H2 items
01:44that have a class of, let's say, inner?
01:50Now, that's the name of the class.
01:52Now, if it's an inner class, don't ask me what it is.
01:54I just invented now that name.
01:56Now, how could I make sure that only if it's an inner class
01:59then it would work that way?
02:01If I only set it to be .inner, that would mean every single inner element
02:10would possess it.
02:12Now, if there's more than one inner element,
02:14that obviously would not work well for us.
02:16If I set it to be H2 with a space, it would mean that any element
02:20inside of our H2 that has an inner, which is not correct at all as well.
02:25Lastly, if we set it to be just anything that's inside of my div that has an inner,
02:30there is a possibility that there will be other items that have an inner as well.
02:34So, the way we solve that is by not putting a space at all.
02:37And what I'm saying here is any H2 item that has the class of inner
02:41then define this rule to it.
02:43And if I go ahead and refresh it, we'll see that our class will look the same.
02:47We'll have still that width, that height of our element as we were expecting it to have,
02:52but it's only happening to this item because it's an inner item.
02:56So, if I go here and I inspect my element,
02:59we'll see that we have here this inner rule and it applies to it.
03:02All right, so there's what we've seen through,
03:05and this also applies also to specific IDs.
03:08So, really, for a specific ID that wouldn't be relevant
03:10because we would just approach that ID directly,
03:13but for a class that would be very, very relevant.
03:15So, that's really the basics of traveling,
03:18and what I want you to do next is go through different HTML elements here
03:22and find ways to travel through using an ID, using a class,
03:27using direct pathing to find yourself being,
03:31get yourself to a position where you're very comfortable using CSS rules.
03:35Now, I'll give you a homework assignment.
03:37I want you to give me two different ways or even, yeah,
03:41like give me two different ways to approach this class called everything,
03:44inside of CSS.
03:46So, give me two different ways or even better off,
03:48come up with a way that was not shown in the comments below,
03:52add one of your own interpretation, any pathing, any direction
03:56that is different than what anyone else has done before.
03:59So, I hope to see that in the comments below,
04:01and I'll comment below, so make sure you also read it and see
04:04because it's really important, these pathing,
04:06very, very important stuff before you move onward.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!