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

Sizing things in different ways

CSS enables to scale elements in many ways. Some ways are relative to the system we are in while others are not. In this lecture we will learn about the differences between them and know how to pick the right measurement system for our needs.

Video Transcript

00:00So far every single sizing we did was absolute. We used pixels
00:05We kind of talked about what they are but not really in this lecture
00:09We're going to talk about all the various critical sizing options that are available to CSS and you'll know the different
00:16Sizings in general, so this is a very very important lecture. Let's jump right into it
00:21It is going to change everything when it comes to how you work with computers
00:26All right, let's talk about relative paths and
00:30Absolute paths for that matter or sizes. We're not talking about path strong with sizes. So
00:36So far we've been working only with pixels and for everything we've put pixels even for font sizes
00:41The problem with defining everything in absolute paths such as fonts
00:47for with pixels is that this means that the size is going to be relative to this amount of pixels per inch in your
00:53Monitor and that could mean that your site is going to look completely different in the size of the text
01:00Depending on what browser the user is in which is a big no-no
01:04It's a big horribleness and that is because what if the fun is going to be too small or too big or not legible?
01:09And that's exactly where it comes into the point
01:13Paths that are not relative and one of the most common ones to use for example with funds is using points
01:20Now instead of putting for example for our h1 here 60 pixels
01:24I'm just going to go ahead here and set it to be 20 points by spray rating PT after the word 20
01:30Now 20 points is an absolute sizing with in other words
01:34The size of our h1 right here is going to look exactly the same way no matter what browser no matter what
01:41Resolution no matter what size the screen the user has no matter what resolution which is a big plus if you want to control
01:48How legible copy is in a browser so obviously 20 points might not be good enough
01:54But I'm going to go ahead here and just set it to be 60 points and you could use fonts
01:59And I want to talk about all the absolute sizes really really quickly
02:02So I'm going to go ahead and what I want to do is I'm just going to put just paste right here
02:07Just a little comment section where I'm just going to lay out all the different paths
02:12so for the absolute sizes, we have centimeters millimeters inches points or
02:18I can't even remember what that is, but it doesn't really matter
02:21What really matters is only that that it's it's called pixas
02:25It's basically two twelve points so for example if I wanted to size my items based on
02:32All of them are very legible all them are very useful all them are very
02:36Supported throughout all the different browsers you could use any one of them now traditionally with fonts usually people use points
02:42And I want to talk further about relative paths because we've seen a few of them already
02:47So I'm going to go ahead here and just paste all of the relative paths that are
02:52Commonly available throughout all the browsers that you could use immediately and we've met already pixels
02:57We've met percentages where we basically put a percentage of that area that we're in so for example if I wanted to go into that
03:05specific
03:07Area of that article I said it with a width of 90% I could have used percentages in any other place
03:13So any place I could use pixels I could also use percentages such as saying I want a 5% margin that is completely
03:19Acceptable now em and ex are a little bit different a little bit more interesting
03:25Ex is rarely used and I'm not gonna talk about it really all it really is is a relative to the
03:32height of the current font
03:34Contrary to the height of the x character of that of a specific font now what I want to do is
03:41Excuse me, I want to focus on the em which is more commonly used which basically enables us to use relative sizing
03:49Now this relative sizing works this way
03:51I could go ahead for my body and decide that in general everything in our body
03:57I want them to have basically a font size a specific font size
04:01Let's say I want my overall font size to be let's say I want it to be 20 points
04:07That's the font legibility that I want it to be so if I go ahead here and click on refresh everything that does not define
04:13In a size will have a specific size of 20 fonts of 20 points now after I set my pixel to be 20 points
04:21Let's see. Let's make it a little bit less dramatic. Let's make it 14 points will be our default
04:25What I really want to do is I want to go to other fonts and derive their size in a relative way
04:31So for example this font seems to be taking that global 12
04:36Points because it was not defined in a specific order specific size
04:40Beyond that so our body basically overrode and set that specific 14 points now
04:46I want to go to my headline my first headline and what I really want to say to it
04:50Hey, by the way, I want you to be three times the size of the normal font to do that
04:55I'll just write 3 em
04:57By writing 3 em my headline right here is going to be three times the size of normal text and I could go ahead into my
05:05Secondary path so my secondary items here. I could go ahead here and say hey by the way your font size is going to be
05:112 em
05:14Which will basically mean twice the size of our regular text and literally in this way I could control
05:21Everything relatively and really if you play around with fonts in general
05:24I would suggest that you'll have one place where you have a controlled font size where all the rest you're putting relative sizes now
05:32The the strength of using point and em is that you could then control for example if you have a mobile site or different
05:38Resolutions where all you have to do is change the font size of your body and it's going to automatically change the layout
05:44Based on the sizes that you think are most appropriate for your users in the relativeness that you want it to be
05:51Which is a wonderful thing so that's it really about sizes
05:55I'm just going to throw in a couple more and I'm not even going to talk about them really and I'm going to put
05:59Them right here, and these are less supported not really commonly supported
06:03So I don't suggest really using them where you have different sizes and different
06:07Controllers and different things that you could do that are just not as commonly supported
06:11But if you want to find out more about them just google them up
06:15I'll try to put a link up in the descriptions or if you find a great resource to put in the link in our
06:20Video so other users could read up about all the different sizes, but in general I would stick to the
06:27Absolute sizes with fonts. I would try to stick to points not because you have to but just because it's a
06:32Convention people tend to talk about fonts and points
06:35pixels for anything else that you want to define and relative to the screen itself or
06:40percentages and then control your fonts using the EM if you want to control different size variations, but have them
06:48Consistently look the same throughout the different experiences that your user has so that's it this covers this topic of sizes and really
06:56This covers any place where we talk in pixels or percentages or points
07:00You could literally play around and put all these different values in
07:03CSS and we'll see you in the next lecture where we can go back into our
07:07Discussion about margins and move on to a new topic that is incredibly similar to margins

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!