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

Avoiding scrolls

Different ways to lay out html elements using CSS. Before we move into this new topic we first want to setup and get our footer ready. By the end of this lesson you will know how to avoid getting horizontal scrolls.

Video Transcript

00:00We're taking a break from learning new things although we're gonna learn an implementation a very common thing is when people have
00:07Horizontal scrolls where your website needs to scroll horizontally and usually that is not a behavior that you want in this lecture
00:14We're gonna take a deeper look into that and see how do you solve that?
00:18How do we fix that problem and in general why you should avoid it? So let's jump right into it
00:23Everything we've done so far when it came to positioning was something that didn't have a name
00:28But really we'll give it a name now. It's called static positioning. That's when we don't actually
00:34Literally tell items where should they be positioned?
00:37But instead of that they're working in a relative way with margins and breaking lines and that way we align and define
00:44Where our elements would be if it's using the float that we've seen and all the other commands that we've seen throughout the last few lectures
00:52The next stage and the next type really of layout is a relative layout
00:57And I want to go ahead and start showing you what does that actually mean?
01:02Now i'm going to go ahead first and what I want to do is I want to change the size of my footer
01:06Because I really wanted to take the full space of our screen. So to do that i'm going to go ahead into my footer
01:13And i'm going to go ahead and just add another command to it
01:16Really? Well, really what I want to do is I want to change my width to be 100 percent
01:22Oh 100
01:24Where is that percent? There we go 100 percent and if I click on refresh, so we'll have a nice long footer
01:30But we've also added a little bit of extra spacing that we really didn't want to have you see this extra scroller
01:37Now if I would undo that change that i've just done
01:41And put their pixels instead and click on refresh. We'll see again. You'll see that there is no extra scrolling
01:46Now the reason is very simple is because our item might have extra padding our item might have extra margins
01:52Our item might have extra things that we want to get rid of so in this case if I set it to be 100 percent
01:58I also want to make sure
02:00What am I doing?
02:01I also want to make sure that their margins or in our case maybe our padding
02:05To make sure that we have no padding that there's zero points for our padding
02:10And if I go ahead here and click on refresh and hopefully now
02:13We don't have any padding and notice how now our size is working perfectly
02:17But our problem is is once we got that we got rid of our padding. We were not really happy with our
02:24Overall the way that it looks like so we might want to just change the padding to the left and to the right
02:29So maybe I'll want to set a padding of
02:33Let's go ahead here
02:35And or just really define a very
02:38Crystal clear. So let me just go ahead here and just set it go to inspect the element and let me just scroll up here
02:44And we're going to select our
02:47Our footer if we could find it. Here we go
02:49Here's our footer and for our padding if i'm going to go here to my height and i'm just going to change that height
02:55Um, our height is 20 of 20 was just not enough because we didn't have any padding
03:00But really we do want to have padding
03:02We just don't want to have padding that is also for our left and right
03:05What we really want to do is we want to have your that, uh zero px for our
03:10Um, um left and right that's where we want it to be zero but for our top and bottom
03:15We actually do want padding and we might want to have even a lot of padding
03:19So we could go ahead here and just find the amount of padding. Oh
03:22Again for our left and right. We want it to be zero there
03:27And for our top bottom then we want to find that right padding that we're happy with
03:32And that is because we set our alignment to be 100
03:35Now another way for us to solve this problem
03:39Is if instead of defining the padding in absolute terms, we could say hey, I want a padding of two percent
03:45But in that case my width I would set it to be 96
03:49And that's literally I could that way I could use a relative pathing
03:52And make sure that i'm not going to have that extra scrolling that we had previously. So that works
03:58Brilliantly for me. All right. So now that we set our footer and it's not
04:04Moving around more than we want it to move around
04:06I'm going to go ahead and I want to add a lot a lot of copy here in between
04:10I just created a few paragraphs before our footer just to start talking about and seeing
04:16How things are working?
04:17so one is we have a problem right away because our copy is now
04:21Aligned to continue the relationship with the last item which was aligned to the left
04:26So what I really want to do is I want to make sure that this rule of clear
04:30Is going to be applied to actually the first paragraph so to do that
04:34I'm going to create a new command that is called clear and I'm just going to go ahead and just move this
04:38Command from our footer and just drop it right in there into the clear class
04:43Now that I have a clear class. I'll just go to that paragraph and just make sure that it's using that clear
04:50And if I refresh then my items are going to break a line
04:53Okay
04:53So now they're breaking a line my footer is in the bottom where I would expect it to be
04:57But what if you wanted your footer to actually be visible at all times?
05:01What if I wanted my footer to be visible even now to create that effect?
05:05I want to change my layout because I want my I want to change it and put it
05:10basically overlapping an item

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!