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

Converting our style into a rule

In the last lesson we learnt how to add style into HTML documents. In this lesson, we turn our code into a rule in order to use it later in our document. We will experience creating our first CSS rule.

Video Transcript

00:00In the last few lectures, we've had our first experiences with CSS.
00:05So far, we've been doing all our CSS directly inside of the item that we wanted to style.
00:11In this lecture, we're going to take a look at how could we take that styling and extract it out to make it into a rule.
00:17So let's jump into it and see what that is.
00:20All right.
00:21So let's continue.
00:22And the next stage of what I want to do is I want to start taking our CSS that we've been creating,
00:28creating these properties that we've been defining or attributes, the properties of CSS
00:33that we've putting directly into the style attribute of HTML.
00:37The problem with that is that it's really hard for us to reuse elements.
00:41For example, if we had a few different titles that we wanted every single body,
00:45or if we wanted to just copy paste this into other projects,
00:48that kind of defeats the point of having all of our styles integrated directly into the HTML.
00:54There is no real separation when we're doing that.
00:57So I'm going to go ahead into my head.
00:59And what I want to do next is I'm just going to type the words style.
01:02That is going to be an HTML property.
01:05And this HTML property enables me to put all the different styles directly into it.
01:10Now, the only difference is now that I'm doing it in this way,
01:14what I have to do is define to whom do I want to put the style.
01:18And then I open and close a round bracket.
01:21All that's left for me to do is to grab all that style rules that I put directly into my body
01:26and just paste them right inside there.
01:28And notice how now we're also getting hints and we're getting colors, color coding.
01:33So I'm going to go ahead here and into my body itself,
01:36I'm going to comment out the style just so you have it,
01:39just in case if you want to look at it in the future.
01:42So, you know, let me just, I'll just grab that.
01:45And I'll just put it right there.
01:47So you'll have it just in case you want to look at it at a future stage.
01:51All right.
01:52So now that we defined our element,
01:54what I'm literally doing is saying, hey, this rules apply to my body.
01:58Let's go ahead and add another rule.
02:00Now, the next rule that I want to do is I want to change the ways HTML elements look like.
02:06I'm going to go ahead and just click on refresh.
02:08And I'm just going to create here a meeting,
02:10because our JavaScript should be still working just as it did before.
02:13Now, notice how already now we have here a link that is being created.
02:17But I don't really don't want this underlined underneath it.
02:21So to solve that, all I really have to do is go to all my elements,
02:25all my items that are A's, all of my links literally,
02:29and just say, hey, by the way, your text declaration from now on is going to be none.
02:35Now, again, a lot of it is just about referring
02:38and knowing what are the options that are there,
02:40or using an editor that gives you hints and makes life much easier.
02:44So once I start typing, I could see the different things that I could set.
02:48So once I know they exist, I don't have to memorize them.
02:51All right.
02:52So that's for my text declaration.
02:54And literally, that's all I had to do to change the way that element looks like as well.
02:59So if I go ahead here and just type something to create here or something,
03:02we'll see that now our link is not going to have an underline anymore.
03:07So that's it about this.
03:08Literally, what I want you to do next is continue on and just find items
03:11that you would want to put rules for them and go ahead and add some rules to them.

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!