How to create RESPONSIVE Layouts with CSS GRID

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ธ.ค. 2024

ความคิดเห็น • 77

  • @coding2go
    @coding2go  3 หลายเดือนก่อน +39

    Since many have pointed out that the fixed offset value of 50.4px is not optimal... You are right! Here is an alternative approach: Instead of using the dev tools to find out the height of the navbar we could
    1. Declare a height to our navbar and use that value for the offset
    2. Make sure to use css units like rem for the navbar's height to account for changes with the font-size
    3. Use box-sizing: border-box; or remove the padding in the navbar so that it doesn't interfere with the height/offset
    New Version:
    nav{
    height: 3rem;
    top: 0;
    position: sticky;
    grid-area: navbar;
    background-color: blue;
    color: white;
    }
    aside{
    height: calc(100vh - 3rem);
    top: 3rem;
    position: sticky;
    align-self: start;
    grid-area: sidebar;
    background-color: grey;
    }

    • @hamza.yusuff20yusuff60
      @hamza.yusuff20yusuff60 3 หลายเดือนก่อน +4

      Take note for those who have padding declared should add the padding top and bottom to the height of the nav.
      Eg
      nav{
      height: 2em;
      Padding: 1em;
      Top:0;
      Position:sticky;
      }
      Aside{
      Height: calc(100vh-4em);
      Top: 4em;
      Position: sticky;
      }

    • @carlosemanuelsalgado4467
      @carlosemanuelsalgado4467 3 หลายเดือนก่อน

      Or just use border box​@@hamza.yusuff20yusuff60

    • @fr3shlian716
      @fr3shlian716 หลายเดือนก่อน

      I have worked with this layout and using rem for the height and top offset of the sidebar will NOT guarantee that these values stay correct if the browsers font size is increased. Instead set the two values in JavaScript dynamically by getting the offsetHeight of the navbar and adding px. Also consider listening to window resizes.

    • @taylorjohnsonct
      @taylorjohnsonct 21 วันที่ผ่านมา

      No, just don't use min-height on body... set it to 100vh.

  • @kareembamidele4804
    @kareembamidele4804 3 หลายเดือนก่อน +13

    My confidence level on css grid just get boosted. Coding2go to the rescue🎉

  • @ryou.6811
    @ryou.6811 3 หลายเดือนก่อน +11

    Great and informative tutorial. You taught in 11 minutes what our professor couldn't the entire semester.

  • @kaustavmanna8908
    @kaustavmanna8908 3 หลายเดือนก่อน +3

    Ossam Bro... Your Work is too good.... My CSS concepts are fine tuned ....
    Love from India 🇮🇳

  • @D7460N
    @D7460N หลายเดือนก่อน

    Thank you for sharing this video!
    Appreciate the emphasis on HTML and CSS semantic simplicity. This really doesn't need to be complex.
    With regard to scrolling the MAIN element while reliably maintaining HEADER and FOOTER elements variable heights without JS or extra comparatively complex CSS, I have found that setting HTML, BODY, APP-CONTAINER (or whatever wrapper your framework gives you), MAIN, and ARTICLE to overflow: hidden, then setting SECTION to overflow-y: auto, assuming that is your direct DOM path from the root element to the scrollable element, allows native browser scrolling bahvior for one to many scrollable elements (SECTION in this case), without JS or extra CSS to track and offset element heights.
    The HEADER and FOOTER element content (plus the content padding/margins) "intrinsically" determine the height of the HEADER and FOOTER. When HEADER and FOOTER element content naturally wrap to the next line, changing their height, the scrollable SECTION elements respond intrinsically.
    This "intrinsic layout" approach has helped avoid the complexities of other techniques, while achieving similar or better results, especially with edge cases.
    Be encouraged and keep up the great work!

  • @Multidimensional.Analyst
    @Multidimensional.Analyst 3 หลายเดือนก่อน +1

    I've just started learning HTML & CSS today. Very informative

  • @asaduzmn
    @asaduzmn หลายเดือนก่อน

    You are so good at teaching any complex topics easily. ❤

  • @MaheshNarayankar-q3d
    @MaheshNarayankar-q3d 6 วันที่ผ่านมา

    Thank you so much 😍

  • @shidi3531
    @shidi3531 3 หลายเดือนก่อน +2

    Great tutorial! Would also style the button to display none outside of the media query 😎

  • @hasibsujon4931
    @hasibsujon4931 3 หลายเดือนก่อน

    I just love this channel because, How this channel will explain the computer language to you is just mind blowing. Even a noob like me feels like a pro when I watch any video of this bro.✌️❤️❤️

  • @oztechph9863
    @oztechph9863 3 หลายเดือนก่อน

    this is what I'm waiting for! Thank you sir! make more tutorial like this

  • @MOHAMMEDKHALANDER-g1c
    @MOHAMMEDKHALANDER-g1c 3 หลายเดือนก่อน +1

    And here we got one more awesome and wonderful video from Grid, yeeehhhh let's go..... thanks a lot sir.
    Love from all coders ❤❤❤.. You are true youtuber and great professor sir, 👏 thank you so much sir.

  • @Aosses
    @Aosses 3 หลายเดือนก่อน

    I use Quickly CSS Grid to build HTML CSS, and it works perfect :)

    • @abdullahfareed3209
      @abdullahfareed3209 หลายเดือนก่อน

      hey, brother do you always use display grid in body like him?

    • @Aosses
      @Aosses หลายเดือนก่อน

      @@abdullahfareed3209 No, if it is not necessary, that will depend on your project or how you want to face the challenge, but review the Quickly CSS Grid documentation, you can also download the template examples that exist and analyze the code for a better understanding.

  • @secretcode96
    @secretcode96 3 หลายเดือนก่อน

    Perfectly Explained.👌

  • @romelloswinton8959
    @romelloswinton8959 3 หลายเดือนก่อน

    Awesome tutorial!

  • @drokard
    @drokard 3 หลายเดือนก่อน +1

    keep working ❤️‍🔥❤️‍🔥✨

  • @mp3prime
    @mp3prime 3 หลายเดือนก่อน

    You are a legend Bro❤❤❤

  • @myfunnyval1
    @myfunnyval1 2 หลายเดือนก่อน +1

    I'm using a screen reader, and trying to follow the video and work at the same time is proving tricky. Is the source code available. Happy to buy you a coffee...

  • @akungtsuper2-o5r
    @akungtsuper2-o5r หลายเดือนก่อน +1

    whos better? flexbox or grid?

  • @muhammad_zohaib936
    @muhammad_zohaib936 3 หลายเดือนก่อน

    Thank you so much ❤🙌

  • @armansrsa
    @armansrsa 16 วันที่ผ่านมา

    is 1fr the same as auto?

  • @nprince411
    @nprince411 3 หลายเดือนก่อน

    thankyou sir usefully video 🥰🙏

  • @wlockuz4467
    @wlockuz4467 3 หลายเดือนก่อน

    Awesome showcase, but I would personally fix the height of navbar and use it as a reference everywhere instead picking the computed height from dev tools.

  • @UbaidAlam-w6f
    @UbaidAlam-w6f 3 หลายเดือนก่อน +1

    which browser do you use

  • @Mr.Useless591
    @Mr.Useless591 3 หลายเดือนก่อน

    Great video

  • @anugrahagomjan6856
    @anugrahagomjan6856 3 หลายเดือนก่อน

    awesome concept

  • @ibrahimhossen6549
    @ibrahimhossen6549 3 หลายเดือนก่อน

    Nice tutorial

  • @IslamicHub12
    @IslamicHub12 3 หลายเดือนก่อน

    Bro.. You are good too much

  • @cecilselormamediku9560
    @cecilselormamediku9560 3 หลายเดือนก่อน

    Excellent

  • @timothyknapp3390
    @timothyknapp3390 หลายเดือนก่อน

    Is there a way to make the side and nav bars modular? Meaning i only need to make a single nav.html file and single side.html file that can get ported into many content pages. That way if my site grows i can alter just a single nav file and the changes take affect across my entire content. By the way i need a client side solution.

  • @kwentoniroy
    @kwentoniroy 3 หลายเดือนก่อน

    Thanks for sharing

  • @ankitxnarwal
    @ankitxnarwal 3 หลายเดือนก่อน

    Hi Sir please start Tailwind CSS ,
    Love from India 🇮🇳

  • @OCEMTechZone
    @OCEMTechZone 3 หลายเดือนก่อน

    Great

  • @brianm5775
    @brianm5775 3 หลายเดือนก่อน

    @coding2GO why did you not use fixed instead of sticky?

    • @brianm5775
      @brianm5775 3 หลายเดือนก่อน

      ahhh i understand...sorry

  • @slowlyshirley8543
    @slowlyshirley8543 3 หลายเดือนก่อน

    Do you know how to make a multipule slide menu, which like H&M website size guide

  • @Dexter101x
    @Dexter101x 3 หลายเดือนก่อน

    Any chance of a grid gallery tutorial?

  • @attaulhaq459
    @attaulhaq459 3 หลายเดือนก่อน

    how you split sceen into two part ?

  • @moncada7112
    @moncada7112 2 หลายเดือนก่อน

    Button doesn't work, what's the conncetion from .show to change the aside, display property to block?

  • @zramdeen
    @zramdeen หลายเดือนก่อน +1

    I had a weird bug when following this. If the main content area has too little content, when resizing, it doesn't get pushed over all the way.
    I fixed it by updating the grid layout in the media query.
    body {
    grid-template-areas:
    "navbar"
    "main"
    "footer";
    }

  • @omtiwary2193
    @omtiwary2193 3 หลายเดือนก่อน +2

    Bro a video on useful tips or cool features of Bootstrap

    • @D7460N
      @D7460N หลายเดือนก่อน

      At the end of the day, it's all vanilla HTML, CSS, and JS in the browser. Less dependencies, the better.

  • @HydroRx
    @HydroRx 3 หลายเดือนก่อน +1

    Should probably calc the height of the navbar and then subtract it from 100vh, using fixed px isn't a good option
    Great showcase tho

  • @Anku-b9
    @Anku-b9 3 หลายเดือนก่อน

    here when 1 view and 1 like

  • @taylorjohnsonct
    @taylorjohnsonct 21 วันที่ผ่านมา +1

    Really should used min-height on body, use height: 100vh, then set overflow-y: scroll on main... now you don't have any of the height styling on the aside or any hardcoding...
    Using hardcoded position values with grid/flex feels reallly bad.

  • @unknown775
    @unknown775 3 หลายเดือนก่อน

    How about a photo?

  • @anitshrestha4227
    @anitshrestha4227 3 หลายเดือนก่อน

    ❤❤

  • @ademineshat
    @ademineshat 2 หลายเดือนก่อน +1

    I'm I the only one noticing that in the video thumbnail is the hamburger menu but something else implemented 😢

  • @ClarkeDesign
    @ClarkeDesign 3 หลายเดือนก่อน

    You can't assume that your nav will always be 50.4px when sizing the aside vertical offset - what is the user agent changes the font size?? Something more dynamic should be used.

    • @coding2go
      @coding2go  3 หลายเดือนก่อน +2

      I hear you! To account for this I recommend to use the unit "rem" instead of pixels. This unit scales relative to the font-size. We would need to apply a height of 3rem for the navbar and then use these 3rem for the vertical offset.

    • @Mustavii
      @Mustavii 3 หลายเดือนก่อน

      plz give a video about css unit. I request you before to leave a video about css unit. Hope that you'll give a tutorial on css unit @@coding2go

    • @armanhossain2491
      @armanhossain2491 3 หลายเดือนก่อน

      ​@@coding2goI tried this but sidebar is going slightly above navbar when scrolling. What to do? Same code. Even in media query it is happening. Thanks in advanceI tried this but sidebar is going slightly above navbar when scrolling. What to do? Same code. Even in media query it is happening. Thanks in advance

    • @coding2go
      @coding2go  3 หลายเดือนก่อน

      @@armanhossain2491 It is possible that you still have the padding applied. That will add a few pixels to the navbar and therefore increase its size. You can use box-sizing: border-box; or simply remove the padding when having a height of 3rem on the nav.

    • @mickdavies5647
      @mickdavies5647 6 วันที่ผ่านมา

      ​@@coding2gothat works great for personal websites, but the moment you're building for corporate, it's only a matter of time before marketing demands for GTM or a CMS to be added and then complains that the layout keeps breaking. Not to detract from your video as it's very well presented and is the best attempt at dealing with a bad design pattern (sidebars are just a bad layout decision IMHO)

  • @StinerDevHub
    @StinerDevHub 3 หลายเดือนก่อน

    ❤❤❤🎉🎉🎉🎉🎉

  • @mikezulu6720
    @mikezulu6720 3 หลายเดือนก่อน +21

    Seeing someone hard coding 50.4 px (inspector value) really hurts. If you learn one thing from this video: Don’t do this.

    • @armanhossain2491
      @armanhossain2491 3 หลายเดือนก่อน +1

      I tried this but sidebar is going slightly above navbar when scrolling. What to do? Same code. Even in media query it is happening. Thanks in advance

    • @AdewaleLuqmaanMudasiru
      @AdewaleLuqmaanMudasiru 3 หลายเดือนก่อน

      What's a better approach?

    • @antonkovachev9181
      @antonkovachev9181 3 หลายเดือนก่อน

      @@AdewaleLuqmaanMudasiruuse framework.

    • @zeusek-2137
      @zeusek-2137 3 หลายเดือนก่อน +15

      You cant say "Don't do this" without telling your approach ;-) thats how internet works

    • @hamza.yusuff20yusuff60
      @hamza.yusuff20yusuff60 3 หลายเดือนก่อน +1

      ​@@armanhossain2491i posted a reply on a comment above.
      The reason for that was the padding . Whatever your padding is you need to add it to the height of the nav eg padding of 2px with a height of 40px will equal 44px
      It's the 44px that will be subtracted from the aside height and will also be the top declaration for the aside.
      Hope this helps.

  • @ayav.7754
    @ayav.7754 หลายเดือนก่อน

    I can't seem to get the button to work?
    Thanks in advance!
    const sidebar = document.getElementById('sidebar');
    function toggleSidebar(){
    sidebar.classList.toggle('show');
    }

    Button
    Navbar

    Sidebar

    Hello world


    Footer

  • @TarunKVasakam
    @TarunKVasakam 3 หลายเดือนก่อน

    Kindly post react topics too. You are explaining everything too well 🫡

  • @xangelcrusadexgaming6807
    @xangelcrusadexgaming6807 2 หลายเดือนก่อน

    i tried to follow all your instructions but when i press the button the side bar wont appear, so i ask copilot for help and copilot suggested adding this code :
    document.addEventListener("DOMContentLoaded", function () {
    const sidebar = document.getElementById("sidebar");
    function toggleSidebar() {
    sidebar.classList.toggle("show");
    }
    document.querySelector("button").addEventListener("click", toggleSidebar);
    });
    and it works!
    Copilot commet is : Ensure your JavaScript is placed correctly, either at the end of the body or within a DOMContentLoaded event listener to ensure the DOM is fully loaded before the script runs.
    I added the code at the end, before closing body tag .Cheers