Adding multiple rules to an element
In the last lesson we added our first CSS rule that gave a background to our HTML page. In this lesson we continue and learn how to add more than one CSS property to the same element.
Video Transcript
00:00In the last lecture, we saw how to define a background,
00:04really seeing how to set our first CSS attribute.
00:08In this lesson, we'll continue down this path,
00:10showing you how to add more than one CSS attribute at a time.
00:14So let's see it in action.
00:16So let's continue.
00:18Now, so far we saw how to create one property,
00:21one attribute, and define it to our body
00:24using the style attribute.
00:26And then we put inside of it CSS rules.
00:29Now, I talked about how in the end of style,
00:33I wanna put a semicolon.
00:35Now, the reason is,
00:35is because I could add more than one property.
00:38For example, with our body, what I really wanna do
00:41is I wanna get rid of the natural padding and margins
00:44that documents have by default.
00:47So to do that, I'm gonna go ahead
00:48and use a CSS property called margin,
00:51and I'm gonna go ahead and define a margin of zero pixels.
00:55Now, notice PX stands for pixels,
00:58and really every display is built off of pixels.
01:01It's a relative measurement count,
01:04which basically is based on how many points
01:06are on our screen.
01:07It is not a definition of actual length,
01:11such as a centimeter or an inch.
01:15Now, the difference between them is that
01:17a screen could have thousands of pixels
01:20or it could have a lot less pixels.
01:22That really depends on something
01:23that's called DPI, or depth per inch.
01:26And you find that different as you buy a new phone,
01:29you'll have more DPI, more resolution,
01:31more vividness in your images and in your elements.
01:35So when I'm counting here in pixels,
01:37I'm saying I want zero pixels.
01:38I'm saying based on the amount of items in the stage,
01:42based on the amount of pixels,
01:43that is my measurement count.
01:44And we're gonna see different types of measurement counts
01:47as we progress, but every single CSS property
01:50could accept relative paths and absolute paths,
01:53but most commonly, we will work with pixels
01:57because it helps us create a commonality
01:59on side of a screen.
02:01So I'm gonna do that for my margin,
02:02and I'm gonna go ahead and also add a padding
02:05or really accurately say I wanna make sure
02:08that there is no padding.
02:10Now, notice in this case, I am not putting a semicolon,
02:13and that is because it's the last property in my style,
02:16and it's just an extra character that's not needed.
02:19So I'm saving a little bit of file size
02:21but not doing that.
02:23And I'm gonna go ahead and click on Save,
02:25and once I do that, if I go back into my application
02:27and click on Refresh, we're gonna see
02:29that everything is gonna be pushed all the way
02:31to the edge of the screen.
02:33Contrary to that, if I went ahead and said,
02:36hey, I wanna have a padding of 100 pixels,
02:38then all of my items would have a padding
02:41around my body that would be of 100 pixels,
02:44growing a lot of padding around our element.
02:47But in our case, that's not what we want.
02:49We wanna keep a very, very tight padding.
02:53So that's it about properties,
02:54and literally you could go ahead into any element,
02:56and I encourage you to do that for a few minutes.
02:58Go ahead and add properties, change colors,
03:01Google, and try to find different properties.
03:03We're gonna discover many of them as we're going along,
03:06but our main focus, again, is gonna be
03:08about the strategy and about the build
03:09because a lot of them are just intuitive.
03:12They're just their name.
03:13Background color is a background color.
03:15Margin is the margins.
03:17Padding is the paddings.
03:18The difference between a margin and a padding.
03:20Margin is external to an item.
03:22Padding is within an item.
03:24All right, so, but we're gonna talk much more
03:28about that as we go along.
03:30What I wanna go ahead now is end this lesson,
03:33encourage you to play around with it a bit
03:35because in the next lesson, what we're gonna do
03:37is we're gonna take what we learned so far
03:38and try to turn them into a rule,
03:41and that's exactly what we're gonna do in the next lesson.
