CSS Grid Course: Positioning Items

Scrimba · Beginner ·🌐 Frontend Engineering ·8y ago
Skills: HTML & CSS90%

Key Takeaways

Covers positioning items in a CSS Grid course using Scrimba

Full Transcript

heyyyyyy in this screencast you're going to learn how to adjust the position and size of the items on the grid which is critical to know in order to create real-world websites with CSS grid we're going to create a mock-up for a website and here in the index.html you can see the mark-up for that as you can see we're targeting each of the items using a class name header menu content and footer to start with we have this 2x2 grid each of the columns are one fraction unit so they're responsive as you can see and each of the rows are 40 pixels tall for our website though we're going to need three rows as we want the header to take up the top row the menu in the content to being on the second row and the footer to be on the third row all the way at the bottom so let's create a third row here let's place in between the two existing rows and give it a height of 200 pixels as you can see now the header and the menu is on the top row on the content and the footer in the second row and our third row is blank as we haven't filled it with content yet since our items only take up the first four grid cells so let's change that we'll start by targeting the header and making it span from the left hand side all the way over to the far right-hand side to achieve that we need to head into the dot header and give it a grid column art set that one and also give it a grid column and ak3 as you can see now the header spans across the entire first row and what we're saying here is that we want the header to start at the first column line and end at the 3rd column line and you might wonder why we have three column lines when we only have defined two columns well that's because the first column line goes from top to bottom on the left side of the grid the second column line is the one that separates the two columns and the third is the one that goes from top to bottom on the far right hand side of the grid so when you have true columns you have three column lines and you can write that like this alternatively though we can also use the shorthand method which I prefer let's remove this line here and also remove - start rather do one for 1/3 as you can see it give us the exact same result let's also do the exact same thing with the footer but now the footer also spans across the entire width well clinically we could have written this in a different way we could have done we could have done one /span - I don't give the exact same result what we're saying is that we want the footer to start at the first column line and span across two columns and finally there's also a third way which is to write minus one that'll target be very last column line now that we know that we want our footer and header to span all the way to the last column line we can do that with both of them and take the advantage of the fact that in the future you might not know how many columns we're going to have in this grid as we can change that however you want so this is a nice little trick when you don't know exactly how many columns the item will span across in the grid and to prove that point for you I'm actually going to change the amount of columns we have in the grid right now because we don't want the menu here and the content to take up an equal amount of space in the width that doesn't make sense we want the menu to be a narrow sidebar on the left-hand side here and we want the content to take up much more space and we could do this without adding more columns by simply doing one fr for fr for example now you can see that the content takes up much more space since the second column is for fraction units and the first column is only one fraction unit however this is not a very flexible way of doing it because now we're still stuck with two columns on a website layout and you normally want a lot more columns than that in order to have the flexibility to shuffle around and change the content so what I'm gonna do instead is use repeat give it twelve columns each of one fraction units now the menu and the content one fraction unit each in other words one column each and they're actually forcing the columns to be as wide as they need in order to display their content or just the descriptions we've added inside items in order to make this look nice again I'm gonna head into the content class and give it a grid column we know that it starts on the second column line two and we want it to go all the way final column line like that so we're gonna do minus one now we have a twelve column layouts instead of a two column layout meaning that we have much more flexibility if you want to shuffle around on stuff and notice that the footer and the header still spans across the entire width which is solely because we're using the minus one here if we had stuck with the three here and here that wouldn't work at all so let's change it back to minus one now let's also look at the grid row property as we're going to need that if we for example want the menu here to span all the way to the top in order to do that we first have to change the header though as we need to make the space here available this little grid cell here needs to be available for the menu so we'll change it to two now we have a blank cell here meaning that we can head into the menu class and give it a grid row and set that 1/3 meaning that it spans from the first row line to the third row line as you can see took up the spots here in the top left corner because this is the first row line this is the second and here is the third the fourth then is of course the the bottom line okay so before we jump onto the next screencast I would recommend you to for example try to make the menu span all the way to the bottom or alternatively make a pair on the right hand side instead of on the left hand side then in the next screencast I'm going to show you a really cool way of defining layouts which gives you a lot of flexibility in terms of shuffling around on the content and experimenting so stay tuned and I'll see you there

Original Description

🎓 View our courses: https://scrimba.com/links/all-courses Check out the full CSS Grid course for free here: https://scrimba.com/g/gR8PTE In this screencast you'll learn how to place items on the grid using grid-column and grid-row. We'll use this technique to create a mockup for a website.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Scrimba · Scrimba · 2 of 60

1 CSS Grid Course: Learn the Basics in 3 Minutes
CSS Grid Course: Learn the Basics in 3 Minutes
Scrimba
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
50 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

Related Reads

📰
Next.js vs Remix vs SvelteKit: Which Framework Should You Learn?
Learn how to choose between Next.js, Remix, and SvelteKit for your next project and why it matters for your career as a developer
Dev.to · Etrit Neziri
📰
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Prepare for a frontend developer interview with Capgemini by reviewing JavaScript fundamentals and practicing common interview questions
Medium · JavaScript
📰
10 Frontend Developer Tools to Boost Productivity in 2026
Boost frontend productivity with 10 essential tools for modern web app development
Medium · Programming
📰
10 Frontend Developer Tools to Boost Productivity in 2026
Boost frontend productivity with top 10 developer tools in 2026
Medium · JavaScript
Up next
The masks we wear | Zora Krstić | TEDxLuxembourgCity
TEDx Talks
Watch →