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

Sticking to our borders

Many developers get confused when it comes to the difference between outline and borders in CSS. They do look alike and do almost the same thing. In this lecture we will learn about the difference between them. In the last lesson we learnt how to work with outlines so why there are separate rules for outlines and borders? By the end of this lecture, you will know the difference between outlines and boarders and how to implement them in CSS.

Video Transcript

00:00The good news is borders are just as easy at outlines and look almost identical in this lecture
00:06We're gonna see them and mainly talk about the differences between them and where do they stand out once against the other?
00:12So let's jump right into it and see it in action
00:15Alright, so let's take a look at another property and to do that
00:19I'm gonna go ahead and I already rent into the HTML and set a new class one called out
00:25One called bore and I just set them all to have six items in parallel in my CSS
00:31I'm just gonna go ahead in my paragraph
00:33and what I want to do is I'm gonna set it to be out for outline and
00:36I'm gonna basically duplicate this and go ahead and create the exact same item
00:42Bush just calling it bore for border as you might have guessed and by the way your reminder
00:48This rule says you have to be a paragraph with the class out
00:52You have to be a paragraph with the class bore
00:55Now if I go ahead and save this and just go back and click on refresh
00:58We'll see that it's more or less gonna render the same thing only now
01:01There'll be a few paragraphs that are not anything because they're not a bore or an out
01:07Now I'm gonna go ahead and show you how to create basically
01:11I'm just gonna comment this out for a second deleting the extra information because you already have it for our outline. It's the same
01:18Basically all the same now, I'm gonna comment out the outline by just putting here a CSS
01:26Comment down and I'm just gonna change the outline to be border. I'm just gonna go ahead here and just copy that
01:33Opa and
01:35I'm just gonna change my border because literally all the properties work and act in the exact same way
01:41I'm just gonna go ahead and set it to be red
01:43So we'll see the actual difference between them and that's it
01:47This is creating our border style with and color now intuitively when you look at it, you'll think well
01:53Isn't this exactly the same thing it is incredibly similar
01:56But it's not and that's the next thing that I want us to look at in this lecture and just before we do that
02:01I'm just gonna showcase really quickly like we were saying just like with the outline
02:05there is that global property that I could literally just go ahead and set it as border and define my
02:12Instance and I'm just gonna go ahead here and set it to be red
02:15So I'm gonna go ahead and click on refresh now that we've seen those four properties
02:19Because my main focus here is the difference between outline and border and when would you want to work with one versus the other?
02:26Now I want you to notice whenever we're in the outline
02:29I'm gonna go ahead here and just change the width of my outline notice the layout does the change of width of my element
02:36Effect my layout. Well, no, although it's growing and starting to overlap the items in their display position are not moving
02:43In other words, the outline if itself does not affect the actual size of the space the element contains
02:51Contrary to that when we approach anything that's inside of the bore
02:55For our border if we change the items pixel
03:00I'm going ahead here and select it if I go ahead and change a pixel notice how everything is getting pushed
03:05And resized to fit to this new shape that is being created
03:10Contrary to the shape change where the item itself has stuck exactly where it was and the outline is not affecting the layout in this
03:17Case not only the outline is affecting the layout of the item
03:20It's also pushing all the items below moving them and affecting them
03:24So that is really the big difference between outline and border. There are a few more small differences
03:31So as we said the outline does not take up space
03:34While the border does
03:36Now the outline
03:38Could have non rectangular shapes. We have not talked about that yet
03:42But once we go into rounded shapes outlines could do that as well, by the way borders could as well
03:48So the difference is really the big differences between the two is that the outline does not affect anything beyond that item itself
03:56Versus the border that does that is really the big difference the big outcome you want to take out of the two now
04:01There's more I want to talk about border that you could do with border currently that you just cannot do with outline and for that
04:07We're going to take a peek at that in the next lecture

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!