Easy sticky footer - stop a footer from floating up a short page!

Поделиться
HTML-код
  • Опубликовано: 27 июл 2024
  • 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 with this method - css-tricks.com/couple-takes-s...
    #css #stickyfooter
    ---
    Come and hangout, ask questions, suggest ideas, and meet some awesome people over in The Community: / discord
    I have a newsletter! www.kevinpowell.co/newsletter
    New to Sass, or want to step up your game with it? I've got a course just for you: www.kevinpowell.co/learn-sass
    ---
    My Code Editor: VS Code - code.visualstudio.com/
    How my browser refreshes when I save: • How to automatically r...
    ---
    Support me on Patreon: / kevinpowell
    I'm on some other places on the internet too!
    If you'd like a behind the scenes and previews of what's coming up on my RUclips channel, make sure to follow me on Instagram and Twitter.
    Instagram: / kevinpowell.co
    Twitter: / kevinjpowell
    Codepen: codepen.io/kevinpowell/
    Github: github.com/kevin-powell

Комментарии • 294

  • @Omar_Thinks
    @Omar_Thinks 2 года назад +18

    I have wasted one day of life trying to do this on my own, and I wasn't successful at it.
    You did it in 5 minutes.
    Thank you bro.
    Great video

  • @RodrigoDAgostino
    @RodrigoDAgostino 5 лет назад +2

    This showed up right when I needed it! :D Thanks a lot, Kevin! Love your humble and friendly style, mate

  • @southgecko3653
    @southgecko3653 5 лет назад +2

    Loving all of your videos and energy. Thank you for being a fantastic teacher

  • @faraztaj849
    @faraztaj849 4 года назад +2

    I've been searching for days how to do this and Margin-top: auto did the trick for me. Thank you so much!

  • @Peter-ur8nv
    @Peter-ur8nv 4 года назад

    Kevin your videos are great and very helpful. Thank you for these kind of content. Keep it up !

  • @stiguybob793
    @stiguybob793 2 года назад

    Thank you so much Kevin, you are the man!!!! I am currently doing your Responsive Website Layout on Scrimba and couldn't figure out how to get the footer to stick to the bottom. Tried for about half and hour just to get that thing down there. There were so many complicated "fixes" to this I tried but none really worked. But your solution worked like a charm!!!! You are very inspiring and I hope to be half as good as you one day.

  • @TheDesignCreative
    @TheDesignCreative 5 лет назад

    Every video is like a gift that keeps on giving . I learn something new.... Love your channel.

  • @igorr4682
    @igorr4682 5 лет назад +2

    As always, clear helpful and well explained video.

  • @jon2394
    @jon2394 2 года назад

    I spent way too much time trying to figure this out. Gave up on the last project trying to achieve this, there are so many "solutions" out there and none of them work. But this one worked flawlessly. Thanks!

  • @digigoliath
    @digigoliath 4 года назад +1

    This is very useful. It is also a solution that I was looking for. Thanks Kevin!

  • @navirosas5968
    @navirosas5968 5 лет назад +17

    Thank you for taking your time to teaching us Kevin 🙇🏻‍♂️

  • @ReinaldoTrindade
    @ReinaldoTrindade 5 лет назад +6

    This channel is a gem!

  • @OrincyWhyteDesigns
    @OrincyWhyteDesigns 2 года назад

    You truly are THE CSS MESSIAH. The flex was such a incredible solution, why did I not think of it ?!?

  • @robby_rice
    @robby_rice 3 года назад +1

    It was really that simple, huh... I seriously spent DAYS trying to figure out some complicated solution LOL thank you so much! I'm new to the web dev world and am taking a crack at making my own blog

  • @ozalisk
    @ozalisk 4 года назад

    Dear Kevin, thank You so much! Brilliant explanation!

  • @EverettCDavis
    @EverettCDavis Год назад

    I remember struggling to get sticky footers to work back in 2012-ish, and it's really amazing how much easier it is now! Even four years ago when this video came out!

  • @felipezampa6537
    @felipezampa6537 Год назад

    I've spent hours trying to fix it using every method possible and none of the worked, but you manage to make my problem solved with basically 4 lines of CSS, thank you very much!!

  • @i_am_hugeng4120
    @i_am_hugeng4120 3 года назад

    Thx, your short tutorial had saved my life, it was killing me always, when faced short content web pages... 🙏

  • @xga3
    @xga3 5 лет назад

    Just what I was looking for! Thank you for sharing.

  • @jani_KA
    @jani_KA 2 года назад

    OMG Thanks so much! I searched for like 2 hours till I found this awesome video. This is the only Video I found that really functions. ❤️

  • @axelschutze4103
    @axelschutze4103 Год назад

    Thank you so much!!! This was the exact information I needed right now. Did really stuck for quite some time. Cheers

  • @Brendan2Alexander
    @Brendan2Alexander 3 года назад +6

    Excellent video. FYI - if you are using Angular, you apply everything explained here, not to the body, but rather to app-root (or whatever your root component is)

  • @379rale
    @379rale 2 года назад +1

    When working with WordPress, there will be some invisible elements in the tag.
    A grid would give each element a row, but flexbox will not.
    So, it's better to use display: flex

  • @fnamelname3209
    @fnamelname3209 2 года назад +3

    If you're using bootstrap this doesn't work currently, but you can do it with bs classes:
    ..

  • @Hasan-ed1fz
    @Hasan-ed1fz 3 года назад

    Very helpful video came across by chance. I just created footer in React and was having this problem. It really helpmed to solve this :)). Thank you!

  • @paraklesis2253
    @paraklesis2253 2 года назад

    Excellent tutorial, as always!!

  • @waasnoode986
    @waasnoode986 5 лет назад +33

    Lol I needed this literally yesterday 😂
    Edit : I still watched and thank you lol

    • @KevinPowell
      @KevinPowell  5 лет назад +4

      Haha, sorry that it was one day late, lol.

  • @Kam1kaze3
    @Kam1kaze3 3 года назад

    Than you so much sir, i really needed that 7 min video straight to the point !!!!

  • @bibhkoutsopoulou879
    @bibhkoutsopoulou879 3 года назад

    Very good video with a good explanation!! I wish i had found your video sooner!! Thank you!! You realy saved me!!!

  • @ChristSadi
    @ChristSadi 2 года назад

    You are my hero!! It took me hours and hours to try to sort this out! thank you

  • @MrGhostSniper95
    @MrGhostSniper95 2 года назад

    Many thanks!!!
    You save me, is very simple but, I was suffering for 3 days trying to fix this.

  • @azizrahaman1605
    @azizrahaman1605 Год назад

    Thanks for sharing amazing thing! keep up the good work

  • @djredtail
    @djredtail 2 года назад

    wow I was searching for this fix so long. You finally helped solve it. Main thing I learned here is the body needs to have a min 100vh. Thanks!!

  • @chaudhryiftikharhussain1997
    @chaudhryiftikharhussain1997 3 года назад

    Thank you! came here after 2 hours try and your way solved it. Thank you

  • @lisarogers5873
    @lisarogers5873 Год назад

    OMG finally. I could not figure out why I would copy and paste the code from my other pages that had the background color go all the way to the bottom but that one shorter page had a white banner on the bottom no matter what I did. I was going out of my mind. Thank you for this fix!

  • @kiliusz
    @kiliusz 5 лет назад +52

    Good video. I wish saw it before my struggling :P

    • @SYPCWAK
      @SYPCWAK 4 года назад +1

      I know exactly how you feel!!

    • @codingworld348
      @codingworld348 4 года назад

      Very true this guy solves all my CSS and HTML problems

    • @ajtube6716
      @ajtube6716 2 года назад

      same here😑

    • @codingcrush
      @codingcrush Год назад

      Same here

    • @goodshiro10
      @goodshiro10 Год назад

      RUclips recommends after we face that problem

  • @chuksjr.1440
    @chuksjr.1440 5 лет назад +1

    Your expression of a stubborn footer at the beginning of the video is so accurate...

  • @kalyansantra3891
    @kalyansantra3891 4 года назад +1

    very helpful video
    and New things I learn that's helpful for me

  • @tevinmorake8924
    @tevinmorake8924 2 года назад

    Ok that was too cool Kevin,
    Thanks for the flexbox idea.

  • @keshan-spec
    @keshan-spec 5 лет назад

    love your vids sir and great explanations.

  • @tahsinalmahi8769
    @tahsinalmahi8769 5 лет назад

    Your tutorials are awesome!

  • @bloopspak
    @bloopspak 3 года назад

    You don't know for how long I've been looking for this

  • @miracleugwu5603
    @miracleugwu5603 3 года назад

    Very helpful video and thank you so much.

  • @envadd.6556
    @envadd.6556 11 месяцев назад

    The King of CSS! Thank you Kevin!

  • @rj.4840
    @rj.4840 3 года назад

    exactly what i was looking for, thank you!!

  • @wg1948
    @wg1948 3 года назад

    Absolute bliss Thank you!!

  • @joseenciso9099
    @joseenciso9099 4 года назад

    Thanks for the simplest solution I have found at the moment :)

  • @mohaumaboe781
    @mohaumaboe781 Год назад

    You're the best, Kevin.

  • @mainamwangi4558
    @mainamwangi4558 Год назад

    Thank you. It was really helpful.

  • @gabiold
    @gabiold 4 года назад +27

    Instead of margin: auto (maybe you want specific margin-top on the footer in case of longer pages), you could use justify-self: flex-end on the footer, and flex-grow: 1 on the main content (above the footer, to fill up the space, otherwise flex-end won't work). And probably justify-items: flex-start on the body so the content will not be centered vertically, if it is short.

    • @SeviersKain
      @SeviersKain Год назад

      or you can do this too:
      body {
      display: flex;
      min-height: 100vh;
      flex-direction: column;
      justify-content: space-between;
      }
      But overall, the Grid-methodology is still the best, because the footer is one hell of a very large sections of a page, it's the best to use Grid to put it in its region where it was supposed to be, the Grid is like having all its component situated already in their own region by using the grid lines. That's what I've tested...

  • @tbm5k
    @tbm5k 5 лет назад +2

    Just what i was looking for 😁

  • @ijohntogun
    @ijohntogun 2 года назад

    Thank you so much this was so helpful

  • @ThriftWarz
    @ThriftWarz Год назад

    thank YOU! was struggling with this

  • @simonnganga1740
    @simonnganga1740 5 месяцев назад

    Bro you are god sent ,spent whole day trying to figure out 😢😢....but finally you came through 😢😂😂

  • @traustitj
    @traustitj 2 года назад +1

    at 2:19 you solved my issue. Thank you so much. The rest of the video is also awesome

  • @devsuper5972
    @devsuper5972 4 года назад

    Nicely done !

  • @suzu6165
    @suzu6165 3 года назад

    my first time watching a css video and finished at by first watching loool ty so much!

  • @AhSoh7091
    @AhSoh7091 5 лет назад +1

    thanks for sharing knowledge

  • @YasutoraChad4ever
    @YasutoraChad4ever 4 года назад

    Thank you so much, it helped me a lot~

  • @TraceyReynolds-he5tt
    @TraceyReynolds-he5tt 8 месяцев назад

    Thank you so much! Spent hours trying to figure out why my footer was stuck in the middle of my short page.

  • @shayama
    @shayama 3 года назад

    Omg finally good vid about that! So good that you explained about height 100% extra. Thank you.

  • @rohanpednekar8074
    @rohanpednekar8074 4 года назад

    Thanks man! This helped me a lot :)

  • @Bhoi_17
    @Bhoi_17 2 года назад

    Thank you for saving my life 🥰

  • @SYPCWAK
    @SYPCWAK 4 года назад

    Thanks for the video!!

  • @omgharajuku
    @omgharajuku 2 года назад

    I just wanna say I appreciate you :)

  • @cristianfz16
    @cristianfz16 3 года назад

    this is so much easier, even the header now became sticky on top, like magic!

  • @Eww...NotTheHumansAgain
    @Eww...NotTheHumansAgain 3 года назад

    Thank you very much!

  • @annasahradyan9849
    @annasahradyan9849 3 года назад

    Thank you very much you are the best!!

  • @dembashow
    @dembashow 2 года назад

    great work

  • @nadishodhana
    @nadishodhana 2 года назад

    Simple solution indeed! The thumbnail to this gives me so much laughter; Thank You

  • @Samarth-ye7bw
    @Samarth-ye7bw 3 года назад

    Thanks a lot sir , It solved my problem with no issues.
    I went through a bunch of sites but none of them were helpful , If It wasn't for you , my footer would've been a mess 😅😅😅
    Thanks again 👍👍👍...

  • @TinyMaths
    @TinyMaths Год назад

    I'm just building my first 'local' website to feature all the apps I've been working on, and ALL of my pages have this issue. Thanks for the fix.

  • @fabr0
    @fabr0 Год назад

    great video kev! i was struggling a lot to do this, mostly because my searches lead to users posting about fixing the footer, which is not easy on the eye. only problem i had was when content or cards had to load, it ends up as in 0:56

  • @UdayaKumaraBro
    @UdayaKumaraBro 4 года назад

    thank you! it was a big help..

  • @ramonplaza21
    @ramonplaza21 5 лет назад

    Awesome video! Thank you! I think this will work too, You can set the body min-height to 100vh then subtract the height of the footer
    body { min-height: calc (100vh - 80px);} 80px is the height of the footer

    • @KevinPowell
      @KevinPowell  5 лет назад

      That would work too! but I don't like setting heights on things though. What if you need to change the height of the footer later (extra line of content maybe)? Then you also need to go and change the height in your calc().

  • @joshuatao7020
    @joshuatao7020 5 лет назад

    Thank you,sir!

  • @AngelGutierrez-ts9ui
    @AngelGutierrez-ts9ui 3 года назад

    Thanks :D It works perfectly.

  • @naimurhasanrwd
    @naimurhasanrwd 5 лет назад

    Extreme Helpful.

  • @ederlima8823
    @ederlima8823 7 месяцев назад

    Wow thanks a lot!! i have this issue on mobile screen and you save me, thank U!!

  • @hg_ofthecity_old_thi
    @hg_ofthecity_old_thi 2 года назад

    Wow thanks Kevin! I thought there is no other solution beside putting more content to fill the space

  • @andyboltondigital
    @andyboltondigital 5 лет назад +3

    Great video Kevin, keep up the great work.
    My method is to:
    1. set body min-height to 100vh
    2. set footer wrapper to position sticky and top to 100%
    I will need to test this more on mobile to see if the issue you mentioned exists and tweak it accordingly.

    • @KevinPowell
      @KevinPowell  5 лет назад +1

      In that case, wouldn't the footer be slightly off the page on a short page?

    • @andyboltondigital
      @andyboltondigital 5 лет назад

      @@KevinPowell it seems to be working ok for me :)
      just mocked up a quick demo for you jsfiddle.net/rezurrection/kse6d3um/9/

    • @TheDesignCreative
      @TheDesignCreative 5 лет назад +1

      This works well on desktop but not so much on mobile.

    • @iceeblister
      @iceeblister 4 года назад +1

      Really like your example. mind if I use it too?

  • @theshelbypalace
    @theshelbypalace 4 года назад

    You're wonderful!!!!! Thank you!!!!

  • @rika7098
    @rika7098 5 лет назад

    THANKS KEVIN .

  • @ashutosh0299
    @ashutosh0299 4 года назад

    I struggled tooooo much......but after your solution.....i am feeling so good...
    Thanks alot Sir...

  • @silassena9306
    @silassena9306 11 месяцев назад

    Thank you!

  • @silvrsurfer
    @silvrsurfer 9 месяцев назад

    I love the creative thumbnail, great video! :)

  • @Anteater23
    @Anteater23 3 месяца назад

    Thanks this helped my problem :)

  • @dominikaschbacher2443
    @dominikaschbacher2443 5 лет назад

    Thanks I always used JS before to fix this issue :)

  • @AlThePal78
    @AlThePal78 Год назад

    I am going to make a video and use this thank you so much : )

  • @alvinyanson
    @alvinyanson 2 года назад

    your thumbnail is very relatable 😂. Thank you so much for this.

  • @stevenespinal5939
    @stevenespinal5939 3 месяца назад

    I'll give it a go. Thanks.

  • @blonduose
    @blonduose 4 года назад

    thank you so much!

  • @Jarlovinss
    @Jarlovinss 3 года назад

    i think i worked OMFG i love you so much man

  • @YuriiHorwight
    @YuriiHorwight 2 года назад

    thanks! very helpful :)

  • @hangtran4863
    @hangtran4863 4 года назад +2

    the p*10>lorem snippet is cool haha thanks

  • @mexiem5778
    @mexiem5778 2 года назад

    thank you so so much!

  • @sev_in_the_sun
    @sev_in_the_sun 3 года назад

    you saved my day!!

  • @DamienPeden
    @DamienPeden 5 лет назад +1

    Some really good notes here! One thing I'd suggest which is what I do with mine (assuming header/main/footer, but can be adjusted) is on the body tag I simply put body{display: grid; min-height: 100vh; grid-template-rows: auto 1fr auto;} and that does the trick just fine with only 3 lines of code. 😀

    • @KevinPowell
      @KevinPowell  5 лет назад +1

      That would work, as long as you go "nav, content, footer" and stick with it :)

    • @KevinPowell
      @KevinPowell  5 лет назад +1

      That would work, as long as you go "nav, content, footer" and stick with it :)

    • @DamienPeden
      @DamienPeden 5 лет назад +2

      You can change the layout simply by updating the grid-template-rows value or using grid-template-areas as well. I always design with header main footer anyway and any content can be placed in the main tags

    • @coronateststation241
      @coronateststation241 Год назад +1

      you saved my life with this

  • @icurcuwl
    @icurcuwl 4 года назад

    Hi Kevin, I was left wondering: why do you choose to use "margin-top: auto;" instead of "align-self: flex-end;"? I'm thinking that using "align-self" would allow you to still use a normal margin on your footer to create a minimal distance to your other content.

  • @DenisYurev
    @DenisYurev 4 года назад

    Thanks, man!!!