8. The Solution Rems - Responsive CSS Tutorial

Scrimba · Beginner ·🌐 Frontend Engineering ·6y ago

Key Takeaways

This video tutorial covers the use of the REM unit in CSS for responsive web design, explaining its benefits and how it differs from the EM unit. The instructor demonstrates how to use REM to create a scalable font size system, and discusses when to use REM versus EM.

Full Transcript

before I go into the solution which is the REM unit I just don't want to poop on the M too much it is a super useful unit and after we've seen these two and we understand where the REM is I'm gonna go into when we might want to choose which one and hopefully make all of it a lot more clear on why both of these are super useful and super important when we start thinking responsibly so the REM is an M but it's short for route m and what does that mean well it means it's always instead of being relative to the parent like the M is it's always relative to the route of our document and I've used the word route a few times and the route of an HTML page is always the HTML element itself that's where a lot of the defaults are coming from even though we haven't actually been styling that in our CSS up until now so you might be wondering how does this make our life easier and let's go and take a look at how so remember right now we get these giant sizes coming and even though this is set to 2m and this is set to 2m this one is getting gigantic it's getting out of control because it's 2m times 1.5 m and it's scaling up and it's a compounding factor that's going on whereas if we use root m we lose that so when my font size is here I'm gonna switch that to an REM instead of an M and the same thing here and the same thing here and the same thing on my headings and let's go and take a look at it right away without doing anything else and look at that this font size is now the same as this font size and this is a lot bigger than this one but that's because I do have my font size set to one and a half RAM here so this font size will be bigger I guess when you're rid of that comment because it doesn't really apply anymore and here we used to have that double compounding factor that was going on my list item was compounding through this which was then compounding again through that if I take this off now and we take a look it's gonna look exactly the same because it's just set to that one size that's relative to the HTML element but you remember that cool thing with m's when I change the font size on my body and everything just worked around that and sort of scaled up and down with that one unit so it's almost like m's and rims are almost like creating a scale instead of creating these font sizes so what we can do is on our HTML element we can set a font size on here so I'm gonna set a font size of 10 pixels and we go and take a look at what that's done everything is shrunk down everything on this page has gotten a lot smaller and if I come on the HTML um in here and I make this 30 pixels everything will have gotten much much much bigger except for this paragraph why hasn't that paragraph gotten bigger what's going on can you figure it out so you remember the paragraph is inheriting its font size the section 2 doesn't have a font size on it nothing that is contained except for the body has it and this is an absolute unit it's not relative to anything we have this in the pixel so this is where it's sitting and it will not change so we so what we've managed to do so if we switch this over from that to one m and then by when am i do mean one R M for font size I'm always going to stick with REMS and you can see here what's happened is everything is going to keep that nice scaling feature where everything is scaling up or down with something else without the possibility of running into that compounding issue now the one thing I wouldn't actually do is set a set font size on my HTML element like this usually I'm just leaving it at the default or I might use a percentage if I need to play with it and you'll see some people recommend setting the percentage really low here to shrink things if you set it to 60 2.5% this makes the default which was 16 now become 10 so when you instead of having to think of one room as 16 pixels and then it's hard to do math like what 16 times 1.5 it's easy now because this is 10 and then that becomes 10 so this is 20 and this is 15 it makes it much easier to think that way I don't do that I you did for a little while because it is easier I will admit but after some time you really do get used to working on this scale of 16 pixels and when you need to scale this up and you're gonna see when we start getting into mobile when we start doing different designs you're going to have on a mobile screen you're probably gonna have a smaller font size and then when you get to a bigger screen you will up the font size so you can up the scale on it but instead of using the percentage maybe you just keep this at 100 as the default and then at the bigger size you just bump it up to 110 and everything or 120 and everything just scales up with it so I tend to just not even bother with this and I leave my REMS like that and play around with it and I've gotten used to doing that and that's how I'm gonna be working through it the rest of this course so you will get a chance to see and I'm gonna explain myself every time I'm using these units especially for the next little while while we're doing them including the next video where I'm going to explain that Em's still do have a purpose we're going to see what the purpose is and how I decide between em and REM and what my for them is

Original Description

🎓 View our courses: https://scrimba.com/links/all-courses This tutorial is a part of "The Responsive Web Design Bootcamp" on Scrimba. Explore the full course here: https://rebrand.ly/responsivebootcamp_yt The rem unit is short for Root em because it is always relative to the font-size of the root of our page. In an HTML document, the root is always our html element. So when we use rems we can keep the nice scaling for font-sizes like we saw with em, but because it is always relative to one single elment, there is no risk of cascading font-sizes that go out of control.
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Scrimba · Scrimba · 50 of 60

1 CSS Grid Course: Learn the Basics in 3 Minutes
CSS Grid Course: Learn the Basics in 3 Minutes
Scrimba
2 CSS Grid Course: Positioning Items
CSS Grid Course: Positioning Items
Scrimba
3 CSS Grid Course: Why Learn It And How It Compares To Bootstrap
CSS Grid Course: Why Learn It And How It Compares To Bootstrap
Scrimba
4 CSS Grid Course: auto-fit & minmax
CSS Grid Course: auto-fit & minmax
Scrimba
5 CSS Grid Course: Implicit Rows
CSS Grid Course: Implicit Rows
Scrimba
6 CSS Grid Course: Fraction Units And Repeat
CSS Grid Course: Fraction Units And Repeat
Scrimba
7 CSS Grid Course: Justify Items and Align Items
CSS Grid Course: Justify Items and Align Items
Scrimba
8 CSS Grid Course: An Awesome Image Grid
CSS Grid Course: An Awesome Image Grid
Scrimba
9 CSS Grid Course: Named Lines
CSS Grid Course: Named Lines
Scrimba
10 CSS Grid Course: auto-fit vs auto-fill
CSS Grid Course: auto-fit vs auto-fill
Scrimba
11 CSS Grid Course: Justify Content and Align Content
CSS Grid Course: Justify Content and Align Content
Scrimba
12 CSS Grid Course: Template areas
CSS Grid Course: Template areas
Scrimba
13 27. Setting up the structure - Responsive CSS Tutorial
27. Setting up the structure - Responsive CSS Tutorial
Scrimba
14 25. Making the navigation responsive - Responsive CSS Tutorial
25. Making the navigation responsive - Responsive CSS Tutorial
Scrimba
15 36. Playing with the title's position and negative margins - Responsive CSS Tutorial
36. Playing with the title's position and negative margins - Responsive CSS Tutorial
Scrimba
16 31. Starting the CSS for our page - Responsive CSS Tutorial
31. Starting the CSS for our page - Responsive CSS Tutorial
Scrimba
17 26. Taking a look at the rest of the project - Responsive CSS Tutorial
26. Taking a look at the rest of the project - Responsive CSS Tutorial
Scrimba
18 15. Spacing out the columns - Responsive CSS Tutorial
15. Spacing out the columns - Responsive CSS Tutorial
Scrimba
19 33. Starting to think mobile first - Responsive CSS Tutorial
33. Starting to think mobile first - Responsive CSS Tutorial
Scrimba
20 22. Making our navigation look good - Responsive CSS Tutorial
22. Making our navigation look good - Responsive CSS Tutorial
Scrimba
21 37. Changing image size with object-fit - Responsive CSS Tutorial
37. Changing image size with object-fit - Responsive CSS Tutorial
Scrimba
22 44. Module Wrap up - Responsive CSS Tutorial
44. Module Wrap up - Responsive CSS Tutorial
Scrimba
23 16. Controlling the vertical position of flex items - Responsive CSS Tutorial
16. Controlling the vertical position of flex items - Responsive CSS Tutorial
Scrimba
24 39. Setting up the widgets and talking breakpoints - Responsive CSS Tutorial
39. Setting up the widgets and talking breakpoints - Responsive CSS Tutorial
Scrimba
25 42. Setting up the About Me page - Responsive CSS Tutorial
42. Setting up the About Me page - Responsive CSS Tutorial
Scrimba
26 35. Changing the visual order with flexbox - Responsive CSS Tutorial
35. Changing the visual order with flexbox - Responsive CSS Tutorial
Scrimba
27 23. Adding the underline - Responsive CSS Tutorial
23. Adding the underline - Responsive CSS Tutorial
Scrimba
28 21. Using flexbox to start styling our navigation - Responsive CSS Tutorial
21. Using flexbox to start styling our navigation - Responsive CSS Tutorial
Scrimba
29 20. Creating a navigation - Responsive CSS Tutorial
20. Creating a navigation - Responsive CSS Tutorial
Scrimba
30 40. Using a new pseudo class to wrap up the homepage - Responsive CSS Tutorial
40. Using a new pseudo class to wrap up the homepage - Responsive CSS Tutorial
Scrimba
31 43. Fixing up some loose ends - Responsive CSS Tutorial
43. Fixing up some loose ends - Responsive CSS Tutorial
Scrimba
32 32. Starting the layout. Looking at the big picture - Responsive CSS Tutorial
32. Starting the layout. Looking at the big picture - Responsive CSS Tutorial
Scrimba
33 24. A more complicated navigation - Responsive CSS Tutorial
24. A more complicated navigation - Responsive CSS Tutorial
Scrimba
34 28. Feature article structure - Responsive CSS Tutorial
28. Feature article structure - Responsive CSS Tutorial
Scrimba
35 34. Styling the featured article - Responsive CSS Tutorial
34. Styling the featured article - Responsive CSS Tutorial
Scrimba
36 18. Making layout responsive with flex direction - Responsive CSS Tutorial
18. Making layout responsive with flex direction - Responsive CSS Tutorial
Scrimba
37 19. flex direction explained - Responsive CSS Tutorial
19. flex direction explained - Responsive CSS Tutorial
Scrimba
38 41. Creating the recent posts page - Responsive CSS Tutorial
41. Creating the recent posts page - Responsive CSS Tutorial
Scrimba
39 17. Media Query basics - Responsive CSS Tutorial
17. Media Query basics - Responsive CSS Tutorial
Scrimba
40 30. Home Page. HTML for the aside - Responsive CSS Tutorial
30. Home Page. HTML for the aside - Responsive CSS Tutorial
Scrimba
41 38. Styling recent articles for large screens - Responsive CSS Tutorial
38. Styling recent articles for large screens - Responsive CSS Tutorial
Scrimba
42 29. The home page.  HTML for the recent articles - Responsive CSS Tutorial
29. The home page. HTML for the recent articles - Responsive CSS Tutorial
Scrimba
43 10. ems and rems   an example - Responsive CSS Tutorial
10. ems and rems an example - Responsive CSS Tutorial
Scrimba
44 1. Starting to think responsively - Responsive CSS Tutorial
1. Starting to think responsively - Responsive CSS Tutorial
Scrimba
45 4. Controlling the width of images - Responsive CSS Tutorial
4. Controlling the width of images - Responsive CSS Tutorial
Scrimba
46 5. min width and max width - Responsive CSS Tutorial
5. min width and max width - Responsive CSS Tutorial
Scrimba
47 3  CSS Units.  Percentage - Responsive CSS Tutorial
3 CSS Units. Percentage - Responsive CSS Tutorial
Scrimba
48 11. Flexbox  refresher and setting up some HTML - Responsive CSS Tutorial
11. Flexbox refresher and setting up some HTML - Responsive CSS Tutorial
Scrimba
49 12. Basic Styles and setting up the columns - Responsive CSS Tutorial
12. Basic Styles and setting up the columns - Responsive CSS Tutorial
Scrimba
8. The Solution Rems - Responsive CSS Tutorial
8. The Solution Rems - Responsive CSS Tutorial
Scrimba
51 14. Setting the columns widths - Responsive CSS Tutorial
14. Setting the columns widths - Responsive CSS Tutorial
Scrimba
52 2  CSS Units - Responsive CSS Tutorial
2 CSS Units - Responsive CSS Tutorial
Scrimba
53 7. The problem with ems - Responsive CSS Tutorial
7. The problem with ems - Responsive CSS Tutorial
Scrimba
54 6. CSS Units. The em unit - Responsive CSS Tutorial
6. CSS Units. The em unit - Responsive CSS Tutorial
Scrimba
55 13. Adding the background color - Responsive CSS Tutorial
13. Adding the background color - Responsive CSS Tutorial
Scrimba
56 9. Picking which unit to use - Responsive CSS Tutorial
9. Picking which unit to use - Responsive CSS Tutorial
Scrimba
57 Tutorial to Learn Alpine JS - Full Course for Beginners
Tutorial to Learn Alpine JS - Full Course for Beginners
Scrimba
58 Guide To Algorithms in Javascript [Binary Search] - Full Course / Tutorial
Guide To Algorithms in Javascript [Binary Search] - Full Course / Tutorial
Scrimba
59 Learn UI Design [7 Fundamentals Tutorial] - Full Course for Beginners
Learn UI Design [7 Fundamentals Tutorial] - Full Course for Beginners
Scrimba
60 Javascript Tutorial for Beginners [From 0 to ES6+] - Full Course
Javascript Tutorial for Beginners [From 0 to ES6+] - Full Course
Scrimba

Learn how to use the REM unit in CSS to create a scalable font size system for responsive web design. Understand the benefits and differences between REM and EM units.

Key Takeaways
  1. Set the font size of the root element using the REM unit
  2. Use REM units for font sizing throughout the CSS
  3. Understand how REM units scale with the root element's font size
  4. Choose between REM and EM units based on the design requirements
💡 The REM unit is relative to the root element's font size, making it a useful unit for creating scalable font size systems in responsive web design.

Related Reads

Up next
We've got separation of concerns wrong
General Musings with Kevin Powell
Watch →