15. Spacing out the columns - Responsive CSS Tutorial

Scrimba · Beginner ·🛠️ AI Tools & Apps ·6y ago
Skills: HTML & CSS80%
🎓 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 A look at the justify-content property, which works with display: flex to distribute content along the main axis (horizontally at the moment). The different values justify-content: space-between will redistribute any extra space in between all the elements, leaving the left-most element to the left, and the right-mots element all the way to the right. justify-content: space-around will redistribute extra space around each element, giving them all an equal amou- justify-content: space-between justify-content: space-evenly is very similar to space-around, but the spacing is more visually balanced.

What You'll Learn

Uses justify-content property with display: flex to distribute content along the main axis in Responsive CSS

Full Transcript

all right so everything in our layout is starting to come together but the problem now is our columns are stuck together so as I mentioned in the last video we can fix this by adding some margin to them but then you have the problem how much margin do you add and then stuff doesn't really fit as well so luckily flexbox has a way to make it a little bit easier and it's something called justified content and this is a new property that we're going to be using we've already seen when we have flexbox when we do display flex this is what's happening right the parent gets display flex and we get columns now we can add a new ping called justified content and there's a few different properties on justified content but one of them is called space between and what that's going to do is it's going to take the extra space that we had that's going to put it between all the elements if we look here as an example we had all this extra space that was left over on the left side so when we add this justified content space between it's taking that extra space and it's putting it in between the columns instead of leaving it over on the right side so what I'm going to do is first I'm going to exaggerate that a lot where I'm gonna change all these numbers but let's make them like pretty small I'm gonna say it's 10 20 and 30% and as you can see then we get all this leftover space and it's just floating over here on the side of our page we get all this empty space like that so what I can do is on where I have display flex so it's always on the parent in the same place that you declared display flex we can then come down and you are just defy the e 5 content so it's just like that two words but they're hyphenated all properties they're always and just like we've started seeing max width is max width with a hyphen in it so justify content is the same and then it will be space between there are two other values you can use we're gonna look at those in a second but this is the one we're gonna be focusing on for now which is space between so now if we go and look at our design we can see that we have this giant space between them because it's taken all that space that was left over on the right side and it's evenly distributed it between our columns now which is awesome now in this exact situation it isn't the best but it is pretty cool now the other two options you do have between other than space between your space around so what space around is going to do is it's also going to put the space on the left and the right space between make sure that the item that's part of this to the left and the item that's farthest to the right stay all the way on the sides whereas space around will put space around each item now the thing that's a little bit weird is the way it evenly distributes that space it's taking the space and it's evenly putting some on the right side of our element here and on the left side and then it's putting some on the right side of this one and on the left side and the right and the left so what that does is it does create this thing where the right space and the left space are always smaller than the spaces in between because it's doubled since this one you're getting equal spacing on each side of each element so these get bigger spaces than on the two ends so more recently they've come up with one that to fix that problem and that one is spaced evenly and what spaced evenly does is it tries to make it visually look like it's balanced this despite width despite anything else it will make all the spaces be even instead of doing that weird space around things so spacing Lee is a really nice solution but for now we're gonna stick with space between and it's probably the one that you're going to be using the most often so we can do now is we can fix the actual widths we had on here now originally we had this as 25 50 and 75 but the problem with that is that doesn't leave any space for our space between to redistribute because when we add all of those up we're always hitting a hundred percent 25 and 25 is 50 plus 50 is 100 and if we come and look down at the bottom we have 75 plus 25 s we have a hundred percent space there as well and so for simplicity now I'm just going to reduce a lot we're make 5% off each one of these so this will become 45 and this one will become 70 so we take 5% off on all of them it's going to leave us a whole bunch of extra space that this space between can now redistribute in between our different items so if we go and take a look we have our nice big gaps in between all of them now everything should be lining up pretty well and it is working out nicely when we go on bigger or smaller screens now it's not a hundred percent perfect cuz our padding is making these columns a little bit bigger than what they were but for the purposes of what we're up to right now I do think it is good enough and it is working really well so I am really happy with it
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Scrimba · Scrimba · 18 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
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 AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →