36. Playing with the title's position and negative margins - Responsive CSS Tutorial
Key Takeaways
This video tutorial explores the use of negative margins in CSS to create a responsive layout, specifically for positioning titles and handling overlapping content. The instructor demonstrates how to use media queries to apply negative margins and achieve a desired layout, while also discussing potential issues and best practices.
Full Transcript
consequence and note so there was one unintended consequence didn't notice before which was we got rid of the spacing on our titles and that got this stuck on this we'll fix this in this video as well but the main focus will be here like I mentioned getting it to pop on over to this side it certain sizes the way I'm going to do it now the reason I'm saying it's not a best practice video as much as a exploration video is because if you had a really long title this would cause some problems there's the potential for overlapping but I just want to show you something that we haven't looked at yet it's something that I try and avoid when I can but I want to show it to you anyway and I think it is fun for the layout purposes on this one and something is worth exploring because while you try and avoid it it's good to know that it is a possibility and that its negative margins so I move all the way down to my layout area we're now all the way down till we find my articles there we go and I'm going to create a new media query because we're going to be dealing with these two pretty much so at media as far as the size of where do I create this media query for don't create media queries based on the size of certain devices or set devices because then you can always do things that you want to do or those devices you know people will make too many media queries because they're trying to match certain devices when they don't need one or in this case I'm trying to really base it on my layout I'm sort of just guessing it the size we're going to tweak it a little bit as we go so I'm going to do 500 pixels for now and let's see if you see how it goes from there so inside my media query what I want to do is select my article recent main and I'm gonna give this a margin top of negative I don't know that's art with negative 1m and to see how that affects things so you can see this sort of gotten a little close together let's just try changing that maybe two negative two you can start seeing these are starting to overlap and we can bring that maybe up to a whole negative three and they're starting to line up how we want them to I'm going to switch that to a 2.5 because I think it's gonna be bang on how I want the top of the text is sort of lining up now as I mentioned this can create text overlap so it's probably not a best practice overall here yeah so this is my longest one so I'm going to base it on this title but what would happen if you have a really long title it would break this whole layout so I'm gonna show you how we can do it with a negative margin so you know if I bring this up really big you can see it's pulling it up on top of other things and it's one of the problems with negative margins but it is important to know you can have a negative margin because sometimes it does come into use and it is useful to have so that is perfect now the other thing I'm going to do in this media query is do my article info and so there's a text aligned to the right and there we go we have the layout that I wanted where we have those going like that now the problem is where's the media query Canyon where is 550 pixels so we're gonna shrink and it's really really close but on this one it's looking perfect so you know it's one of those ones where you have to judge it by eye a little bit I'm gonna bump it up to 550 just because I don't want those to get so close to each other so it gives us this small little range where we have two columns and then where it pops over back to the big layout where we're gonna have to change what that looks like anyway so that is how we can go and do something like that with a little bit of hackery to give ourself this fake two column look based on the way our markup is but again make sure you keep this really really simple because it's keeping cooking simple but if this was how to keep your cooking simple all of a sudden I'm a little worried we have overlap and it's causing problems so while negative margins can be fun for creating cool layouts or cool effects sometimes and sometimes you want overlapping content it's always possible you want two things to sort of overlap and there's other ways of doing it with positioning as well which we're going to explore later but just when you use the negative margin be very very aware that this is a possibility so I think what I'm going to do is while we've explored it while we've seen it you want to sort of rebuild this on your own at one point and keep it in your code because I do think it looks really nice with how I've set this up it's just not something we can do in a responsible way so we've looked at how to do it but now we're just going to take it all off because I think it's going to cause more problems in the long run and it's really important that you keep your code as functional as possible and that it can accommodate for all these situations so if you're ever putting together a demo site make sure you don't only use short text it's real like if you're doing a business card template don't is a really short name Kevin Powell is not a good name to use you want to get a really really long name on the template to make sure that it can work with super long names and it's not running into issues so the same thing here we you want to test short titles and long titles to make sure everything will work with your code
Original Description
This tutorial is a part of "The Responsive Web Design Bootcamp" on Scrimba. Explore the full course here: https://rebrand.ly/responsivebootcamp_yt
We can use negative margins for some pretty creative stuff, and in the right situation it might be the right thing to do, but we have to be really careful with them and make sure that it doesn't cause any problems.
Playlist
Uploads from Scrimba · Scrimba · 15 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
▶
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
CSS Grid Course: Learn the Basics in 3 Minutes
Scrimba
CSS Grid Course: Positioning Items
Scrimba
CSS Grid Course: Why Learn It And How It Compares To Bootstrap
Scrimba
CSS Grid Course: auto-fit & minmax
Scrimba
CSS Grid Course: Implicit Rows
Scrimba
CSS Grid Course: Fraction Units And Repeat
Scrimba
CSS Grid Course: Justify Items and Align Items
Scrimba
CSS Grid Course: An Awesome Image Grid
Scrimba
CSS Grid Course: Named Lines
Scrimba
CSS Grid Course: auto-fit vs auto-fill
Scrimba
CSS Grid Course: Justify Content and Align Content
Scrimba
CSS Grid Course: Template areas
Scrimba
27. Setting up the structure - Responsive CSS Tutorial
Scrimba
25. Making the navigation responsive - Responsive CSS Tutorial
Scrimba
36. Playing with the title's position and negative margins - Responsive CSS Tutorial
Scrimba
31. Starting the CSS for our page - Responsive CSS Tutorial
Scrimba
26. Taking a look at the rest of the project - Responsive CSS Tutorial
Scrimba
15. Spacing out the columns - Responsive CSS Tutorial
Scrimba
33. Starting to think mobile first - Responsive CSS Tutorial
Scrimba
22. Making our navigation look good - Responsive CSS Tutorial
Scrimba
37. Changing image size with object-fit - Responsive CSS Tutorial
Scrimba
44. Module Wrap up - Responsive CSS Tutorial
Scrimba
16. Controlling the vertical position of flex items - Responsive CSS Tutorial
Scrimba
39. Setting up the widgets and talking breakpoints - Responsive CSS Tutorial
Scrimba
42. Setting up the About Me page - Responsive CSS Tutorial
Scrimba
35. Changing the visual order with flexbox - Responsive CSS Tutorial
Scrimba
23. Adding the underline - Responsive CSS Tutorial
Scrimba
21. Using flexbox to start styling our navigation - Responsive CSS Tutorial
Scrimba
20. Creating a navigation - Responsive CSS Tutorial
Scrimba
40. Using a new pseudo class to wrap up the homepage - Responsive CSS Tutorial
Scrimba
43. Fixing up some loose ends - Responsive CSS Tutorial
Scrimba
32. Starting the layout. Looking at the big picture - Responsive CSS Tutorial
Scrimba
24. A more complicated navigation - Responsive CSS Tutorial
Scrimba
28. Feature article structure - Responsive CSS Tutorial
Scrimba
34. Styling the featured article - Responsive CSS Tutorial
Scrimba
18. Making layout responsive with flex direction - Responsive CSS Tutorial
Scrimba
19. flex direction explained - Responsive CSS Tutorial
Scrimba
41. Creating the recent posts page - Responsive CSS Tutorial
Scrimba
17. Media Query basics - Responsive CSS Tutorial
Scrimba
30. Home Page. HTML for the aside - Responsive CSS Tutorial
Scrimba
38. Styling recent articles for large screens - Responsive CSS Tutorial
Scrimba
29. The home page. HTML for the recent articles - Responsive CSS Tutorial
Scrimba
10. ems and rems an example - Responsive CSS Tutorial
Scrimba
1. Starting to think responsively - Responsive CSS Tutorial
Scrimba
4. Controlling the width of images - Responsive CSS Tutorial
Scrimba
5. min width and max width - Responsive CSS Tutorial
Scrimba
3 CSS Units. Percentage - Responsive CSS Tutorial
Scrimba
11. Flexbox refresher and setting up some HTML - Responsive CSS Tutorial
Scrimba
12. Basic Styles and setting up the columns - Responsive CSS Tutorial
Scrimba
8. The Solution Rems - Responsive CSS Tutorial
Scrimba
14. Setting the columns widths - Responsive CSS Tutorial
Scrimba
2 CSS Units - Responsive CSS Tutorial
Scrimba
7. The problem with ems - Responsive CSS Tutorial
Scrimba
6. CSS Units. The em unit - Responsive CSS Tutorial
Scrimba
13. Adding the background color - Responsive CSS Tutorial
Scrimba
9. Picking which unit to use - Responsive CSS Tutorial
Scrimba
Tutorial to Learn Alpine JS - Full Course for Beginners
Scrimba
Guide To Algorithms in Javascript [Binary Search] - Full Course / Tutorial
Scrimba
Learn UI Design [7 Fundamentals Tutorial] - Full Course for Beginners
Scrimba
Javascript Tutorial for Beginners [From 0 to ES6+] - Full Course
Scrimba
More on: HTML & CSS
View skill →Related Reads
📰
📰
📰
📰
Stop installing giant icon packages — write SVGs as source with a CLI + MCP
Dev.to · arialus
Frontend Engineers Are Quietly Becoming the New Overhead.
Medium · AI
Building an Interactive Fashion Hero with HTML, CSS & GSAP
Dev.to AI
Out-of-Order HTML Streaming Moves from JS Frameworks into the Browser
InfoQ AI/ML
🎓
Tutor Explanation
DeepCamp AI