Body extends below footer

Does anyone know why the body extends below my footer on smaller screens ? and there's no fix height so I don't understand what's going on.. https://codepen.io/Antony-Collin/pen/WNYejKZ
45 Replies
StefanH
StefanH•13mo ago
Old vid but this should help https://youtu.be/yc2olxLgKLk
Kevin Powell
YouTube
Easy sticky footer - stop a footer from floating up a short page!
Having the footer of the page just floating around in the middle just looks... bad. So let's see how we can fix it with both flexbox and grid in this video! As an added bonus, both of them are really easy to do! This CSS-Tricks articles has a few other ways, including different ways to do it with flexbox and grid in case you run into issues wit...
QuEEb
QuEEb•13mo ago
thanks, will check it out
StefanH
StefanH•13mo ago
Html is quite devious that way. Your background may extend all the way down, but the actual div or whatever doesn't
QuEEb
QuEEb•13mo ago
does the video explain how to stop my body at my current footer position or how to stick my footer all the way down my current body ? because I would rather the first option, idk if it's possible tho
StefanH
StefanH•13mo ago
What do you mean with "stop the body at your footer position"?
QuEEb
QuEEb•13mo ago
I would like my full page to be this long instead of just adjusting my footer down
StefanH
StefanH•13mo ago
Well, the browser is gonna be as tall as the user wants You cant resize the window. That goes against everything web design is about You could have your content centered at the page
QuEEb
QuEEb•13mo ago
I'm not sure I understand, I thought the height of the page is as long as it needs to be to fit the content
StefanH
StefanH•13mo ago
And then the footer at the bottom. That would make best use of the screen space Yeah. I don't understand what your goal is If the window is taller than your page, it'll just end halfway through
QuEEb
QuEEb•13mo ago
got you ! I got confused I guess. I will check the video for cases where the window becomes taller
StefanH
StefanH•13mo ago
For this page i'd recommend moving the footer down and then centering your content vertically I've made home pages like this before. Works pretty well
QuEEb
QuEEb•13mo ago
can I just use vertical align to center the content ?
StefanH
StefanH•13mo ago
No, that property only applies to text. It doesnt do what you think it does I'd use flex-grow on the middle div to have it fill the vertical space and then use another flex or grid container tk center your content in there Making a codepen one sec
QuEEb
QuEEb•13mo ago
I fixed the footer now I just need to center the content
QuEEb
QuEEb•13mo ago
StefanH
StefanH•13mo ago
is codepen down? ok ok
/* The thing you applied flex-grow: 1 to */
main {
display: grid;
place-items: center;
}
/* The thing you applied flex-grow: 1 to */
main {
display: grid;
place-items: center;
}
QuEEb
QuEEb•13mo ago
it works for me
QuEEb
QuEEb•13mo ago
I don't know what I did wrong but it doesn't seem to fix https://codepen.io/Antony-Collin/pen/WNYejKZ
StefanH
StefanH•13mo ago
oh you added margin-top: auto to the footer i prefer using flex-grow for this because then the main content always fills the page
QuEEb
QuEEb•13mo ago
so flex-grow: 1 for the footer ?
StefanH
StefanH•13mo ago
Or actually i've been using grid lately Wait i'll make a codepen
QuEEb
QuEEb•13mo ago
thanks for your time, I appreciate it
QuEEb
QuEEb•13mo ago
it kinda works but displays my flexbox vertically
StefanH
StefanH•13mo ago
Can you update your codepen? Also probably good to only have a single div in main. just wrap both your divs in an empty div
StefanH
StefanH•13mo ago
Also that should be a heading tag of some sort
StefanH
StefanH•13mo ago
Doesn't look any different to me?
QuEEb
QuEEb•13mo ago
I want my flexbox to display it like this but centered, I don't want the items to be vertical
StefanH
StefanH•13mo ago
I can't see the changed version on codepen. Still using the old methods for me
QuEEb
QuEEb•13mo ago
ah, ok oops https://codepen.io/Antony-Collin/pen/WNYejKZ do you see it now ?
StefanH
StefanH•13mo ago
Yes
QuEEb
QuEEb•13mo ago
StefanH
StefanH•13mo ago
Issue is you accidentally changed your .games to have display: grid lol That should be flex. Guessing that's a mistake
QuEEb
QuEEb•13mo ago
you are right, but if I'm not mistaken, .games doesn't seem to be centered
QuEEb
QuEEb•13mo ago
is it ? idk
StefanH
StefanH•13mo ago
No. It doesn't seem like you implemented my suggestions in the codepen
StefanH
StefanH•13mo ago
you're still using the giant footer margin here
QuEEb
QuEEb•13mo ago
I have no idea... I'm trying https://codepen.io/Antony-Collin/pen/WNYejKZ you're there ? @stefanh
StefanH
StefanH•13mo ago
this is the stuff you need to replicate
StefanH
StefanH•13mo ago
look at my example code and apply it to yours
QuEEb
QuEEb•13mo ago
I tried and it's not working
vince
vince•13mo ago
I wouldn't use vh units here. You can apply height: 100% to html tag and min-height: 100% to body tag Really it shouldn't make a difference in this case I don't think but imo it's better to just completely avoid vh/vw units when you can
StefanH
StefanH•13mo ago
vh is perfect for this. note that it's a min-height, not a height i used to set min-height 100% on html and body too but this is faster and i can't see any negative side effects viewport units are often discouraged because people use them for dynamic font sizes, but even then, they're fine as long as you clamp them
vince
vince•13mo ago
Yea I agree with you, but I think if someone is new to css it's better to avoid viewport units because it's an easy trap to fall into, since there's a lot of nuances that someone who is new might not know Just my 2 cents
Want results from more Discord servers?
Add your server
More Posts