Adding Outlines to shapes
Over the last few lectures we were playing with colors of elements focused on their content. In this lecture we move out of our shapes and learn how to control their outlines. By the end of this lesson, you will know how to define CSS outlines to shapes.
Video Transcript
00:00In CSS, there are outlines and there are borders.
00:03They're almost the same.
00:05You won't notice the difference unless you know it.
00:07And in the next two lectures,
00:09you're gonna learn the differences
00:10and know when to use one while using the other.
00:13And we're gonna start off with outlines.
00:15So let's jump right into it,
00:16see what they are and how they work.
00:19All right, so let's see how could we create outlines
00:21around really any HTML element.
00:24In this case, we're gonna go ahead
00:25and add to every paragraph an outline.
00:29So I'm gonna go ahead
00:30and I'm just gonna scroll down
00:31and just create that paragraph rule
00:34because I want it to apply to all these paragraphs
00:36that we created in our HTML.
00:39To create this outline, literally all I wanna do
00:42is I'm gonna go ahead here and set first an outline style.
00:46And the style itself is gonna define
00:48what type of styling is gonna be applied.
00:51Now, if I don't go ahead and set a style
00:54and just go right out there and do create an outline width
00:58and set it, let's say, to one pixels
01:00and I go ahead and I click on refresh,
01:02what's actually gonna happen is not much.
01:05The reason is is because I don't have a style configured.
01:08So I really have to configure a style
01:10before I could actually start manipulating
01:12and seeing the items.
01:13And that is because the default value is none,
01:16which basically makes it invisible.
01:19So I'm gonna go ahead and create a solid line
01:21by setting that to be our outline style to be solid,
01:25setting it to one pixels.
01:26So now we've seen how to define the width of our item
01:31by saying it's gonna be one pixel long.
01:34I'm gonna go ahead there and save my item
01:36and click on refresh and you'll see
01:37that now I have an outline of one pixel.
01:40Notice in my CSS, I could go ahead here in my pixel
01:44and I wanna really talk to you
01:45about what these pixels really are.
01:48We've talked about it briefly,
01:50but every screen has basically a DPI depth per inch.
01:54And really that just means is that in an inch,
01:56if this is, for example, on my computer an inch,
01:58on your screen it might be a lot less than an inch.
02:01The reason is very simple
02:03is because your device might have less pixels.
02:06Now literally because the amount of pixels
02:08that I have on my screen,
02:09the size of items are different than different screens.
02:11And that is why you could watch the same website
02:14on a browser that's on a desktop
02:17that has 40 inch screen
02:19or a browser that is on your mobile device.
02:22So pixels are a relative measurement
02:24and that relative measurement is based on how much
02:26basically points are on your user's screen.
02:30In this case, if I set it to be two pixels,
02:32I'm basically saying use two points in our screen system.
02:35That's not a measurement that you could measure
02:37with a ruler because it would be different
02:39in different screens.
02:40But it will take the same space
02:43and amount of resolution based on how much items
02:46are in that resolution.
02:47So based on my resolution
02:48and based on how many pixels on my screen,
02:50the way it would render would be different,
02:53which is really good because we want relative outputs
02:56inside of our display.
02:57So there we go.
02:58So that is our style and that is our width.
03:00There's only one more thing
03:01that we really wanna cover of the basics
03:03and that is basically color.
03:05And as you might've guessed,
03:06your back outline has a color as well.
03:09And I could put there any color value
03:11as we talked about in previous courses.
03:13I'm gonna, chapters that is,
03:15and I'm gonna go ahead and just set it to white.
03:18I'm not gonna talk too much about that
03:19because you're familiar with colors.
03:22We've talked about them a lot.
03:23You could put here any value that is a valid color value.
03:27Now, I wanna show you also how to combine
03:30all these two together, but before that,
03:32I just wanna put here all the different styling options
03:35that you could have for your outline style definitions.
03:38There's quite a lot of them.
03:39So I'm not gonna go over every single one of them.
03:42I'm just gonna go ahead and paste it here
03:43so you could have a good view.
03:45And let me just set here a word wrap
03:47so we could see everything.
03:49So our default is none.
03:51We're not gonna talk about the difference with hidden,
03:53and that is because this is relatable more for tables.
03:56So when we go to talk about tables in a future course
03:59on CSS, you're gonna see also in-depth of the hidden.
04:02So you could skip the hidden item
04:04and look at none, dotted, dashed, and so on and so forth.
04:07I'm gonna go ahead here and set it to be inset
04:11instead of solid.
04:12And that will cover really this topic
04:15before we move on to one last property in this video.
04:17And you'll notice how we're creating
04:19like this boxy type of effect.
04:21And to make it a little bit more noticeable,
04:23I'm just gonna go ahead here in my width,
04:25and I'm gonna set my width to my paragraph
04:28to, let's say, 300 pixels.
04:30And really what I'm doing here is saying,
04:31hey, this paragraph, don't take the full width
04:33of the screen, just take 300 pixels.
04:36By doing that, I'll be able to see that box more clearly,
04:39and you can see that inset going on inside of that box.
04:43Now, one more thing that I wanna talk about
04:45is how do we connect all of these outline rules
04:48all together, and again, it's very, very simple.
04:51I'm just gonna go ahead here and just comment out
04:53all these styles that we've set here,
04:55or let me just go ahead here and just delete that,
04:58and I'm just gonna set all of that into a comment.
05:02And I'm gonna go ahead and create the outline.
05:05Now, the outline itself, except basically a color,
05:09and we wanted it to be white.
05:12It accepts, after a space, the style itself.
05:15In our case, we want it to be inset.
05:17And it accepts a width, and for our case,
05:20we wanted it to be one pixel in width.
05:22And there we go, so we could set all of what we've just
05:25done previously in one simple, small rule.
05:28And again, these are things you're gonna see very commonly
05:31is after we talk about the big, every single item
05:33separately, that we could control the items directly
05:36with a shorthand ruling.
05:38Now, if I go ahead and I save this,
05:40you'll see that it's the exact same sample.
05:42We're not done talking about outlines and borders,
05:45and we're gonna continue talking about in the next lecture,
05:48so we're gonna see in the next lecture as we dive
05:50a little bit deeper into this topic.
