Learn how to create a responsive CSS grid layout

Поделиться
HTML-код
  • Опубликовано: 2 июн 2024
  • A look at how we can make a dynamic, responsive grid using CSS, along with a dive into properties l like aspect-ratio, object-fit, and more.
    🔗 Links
    ✅ The GitHub repo: github.com/kevin-powell/dynam...
    ✅ Andy Bells CSS reset: piccalil.li/blog/a-modern-css...
    ✅ My Emmet video: • Use Emmet to up your H...
    ✅ The easy way to get started with CSS grid: • Learn CSS Grid the eas...
    ✅ About object-fit: • How to use CSS object-...
    ✅ Auto-fit vs Auto-fill: • The magic of auto-fit ...
    ✅ More about aspect-ratio: • Chrome 88 adds aspect-...
    ⌚ Timestamps
    00:00 - Introduction
    01:01 - Writing the HTML
    04:57 - Setting up a basic grid
    06:39 - Styling the cards
    07:23 - Using aspect-ratio on the images
    10:03 - Stacking content with grid
    13:01 - Styling the card content
    14:03 - Adding aspect-ratio to the cards
    18:52 - Making the grid dynamic with auto-fit
    22:31 - Creating a featured card
    25:59 - Styling the featured card
    28:49 - Fixing things for small screens
    #css
    --
    Come hang out with other dev's in my Discord Community
    💬 / discord
    Keep up to date with everything I'm up to
    ✉ www.kevinpowell.co/newsletter
    Come hang out with me live every Monday on Twitch!
    📺 / kevinpowellcss
    ---
    Help support my channel
    👨‍🎓 Get a course: www.kevinpowell.co/courses
    👕 Buy a shirt: teespring.com/stores/making-t...
    💖 Support me on Patreon: / kevinpowell
    ---
    My editor: VS Code - code.visualstudio.com/
    ---
    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.
    Twitter: / kevinjpowell
    Codepen: codepen.io/kevinpowell/
    Github: github.com/kevin-powell
    ---
    And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!

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

  • @nielslytzdk
    @nielslytzdk 2 года назад +97

    Kevin is best CSS teacher on RUclips. Period. It's an absolute delight watching his videos and you learn so much :)

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

      AGREED!! I would probably have to stop my web development without his css help lol!

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

      100% Agreed. For example when I need some tutorial in JS or React I search for random people but when it comes to CSS I know one place for sure it is this channel. Thank you Kevin for the job that you do for us 🔥🙌🏼

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

      By far! I found him on a css battle video and Ive learned more from him than I have in school.

  • @iLikeMyOwnPosts
    @iLikeMyOwnPosts 2 года назад +47

    Kevin, I just discovered you a few weeks ago and have been watching like crazy. I needed something just like this for a project I am working on this weekend. Perfect timing, happy new year!

    • @KevinPowell
      @KevinPowell  2 года назад +6

      Welcome aboard! Glad that you're enjoying my content!

    • @fernando-2160
      @fernando-2160 Год назад

      Ahh hh hum hh

  • @WellSaint001
    @WellSaint001 2 года назад +13

    Man, you truly are a dev hero!!
    It feels weird that a couple months ago I didn't know about your channel, and now I'm trying hard not to miss any of your videos. Also, double thanks for letting us know more about css-grid.

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

    I've watched so many of your videos now and with each new video I watch I keep thinking of how much I learn from you. Kevin, you're amazing. Please keep doing what you're doing.

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

    Kevin - dude, you are simply an amazing teacher - thank you so much for all your hard work - cannot wait to see what this year brings

  • @tedbailey6530
    @tedbailey6530 Месяц назад

    Love the video. I never really knew the ins and outs of grid. You nailed it. Thanks, Kev.

  • @hcf797
    @hcf797 2 года назад +9

    Yes! Please do a video on optimization. I spend so much time trying to optimize, making different sizes for the same img, etc., that I’m sure there is an easier way. Thanks for all you do, Kevin.

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

    The full outline of how to really use aspect-ratio makes me really happy.

  • @asyncawaited
    @asyncawaited 4 месяца назад

    I subbed to your channel the moment I started watching some of your other videos. I must say you are a true master of CSS, but the thing that's so strikingly humorous and fun for me is the continual "we're going to fix that!" in your videos. I love how fun you make it and it's so refreshing to be able to chuckle and know that no matter how many times you break something for the sake of a good tutorial, it's going to get fixed; because you're a master of your craft. Thanks for making learning fun!

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

    Kevin, I cannot thank you enough for all this wonderful knowledge that you’ve shared. You have helped me become such a better programmer. Thank you!!!

  • @aaroonplay1993
    @aaroonplay1993 6 месяцев назад

    No doubt about it, every time i have struggled with css, this is the place to come. thanks a lot.

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

    man, these videos are amazing. I thought I was a master at css grid but still learned a few new things in this video

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

    Cant describe what you have openned my eyes, Kevin!!! Thank you so so so much!!!

  • @junkboxrobots3309
    @junkboxrobots3309 Месяц назад

    Awesome, dude. Love the video. I had forgotten grid structuring in css and I love your explanations best. I'm going to watch your other stuff as well.

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

    I am doing my homework and was stuck with the grid layout for the whole day, and then, I found your video! definitely saved me! thank you so much for this fantastic video.

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

    You're truly the best. Bingeing your channel for the past few months. Sincerely, thank you!!!

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

    Seeing you so happy with grid makes me so happy :)
    Great video!

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

    😮Just discovered o haven't subscribed after week of watch your tuitorials, Kelvin you're a saviour to we beginners

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

    Thank you Kevin, your channel is a web tool. Always learning new things from you

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

    Thanks for the grid lesson Kevin. Help me so much 🙏🏼

  • @5555Elenka
    @5555Elenka 2 года назад +3

    С рождеством и наступающим Новым годом Кевин ! Крепкого здоровья Вам и вашей семье ! Спасибо за уроки )С наилучшими пожеланиями !!! 👍👍👍🎅🐯🌲💥💥💥

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

    I'm a bit late with this but thanks Kevin I've just finished a big real world project for a client and this video nailed it for me!

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

    One of the best teachers I've seen

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

    That was great. You have also focused on Aspect Ratio as well. Especial thanks for that.

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

    Love all your videos, Im creating my own site and you help me out a lot!

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

    So much excellent information here. Thanks!

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

    Very helpful guide! Thank you

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

    Thank you! Now I know grid-template-columns: repeat(auto-fit, minmax(x,y)) and aspect ratio better.

  • @LogicalAmericanMuslim
    @LogicalAmericanMuslim Месяц назад

    bro, you are awesome! I recently started building responsive pages and this video helped me alot! thank you

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

    Hey Kevin your videos are awesome, thank you so much!

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

    Nice tutorial worked perfectly for creating a home page of apps

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

    Kevin, first of all congratulations on your amazing work with your RUclips channel and your courses elsewere, you are an amazing teacher. On with my question now, where did you got this T-shirt, I want one too!

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

    Kevin, wish you all the best!

  • @mahmoud-bakheet
    @mahmoud-bakheet 2 года назад +1

    I’m always watch your videos whatever that you’re providing , I hope you always be continued we love your videos and the way that you coding ❤️❤️

    • @KevinPowell
      @KevinPowell  2 года назад +2

      Thanks Mahmoud! I've got no plans to stop anytime soon!

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

    Hands down for this legend 🙏🏻💯🙌

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

    Awesome! Thank you Kevin!

  • @NovaKirsch
    @NovaKirsch 8 месяцев назад

    Merry Christmas, Kevin

  • @m.albehery
    @m.albehery 2 года назад

    one of the best videos I have ever seen

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

    Thank you so much Sir for this tutorial, it saved my life.❤❤❤❤❤

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

    so simple, so clean, so nice :)

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

    Just great vid :) Very useful and clear

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

    I have a question, when you creating a layout do you practice this before you start the vlog or do you do this on the spot?
    Thanks im a new subscriber and i love your tutorials specially css grid.

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

    Amazing Teacher!!!

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

    Thanks, this is super useful!

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

    WOW , Thats great video man

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

    Thanks for another great video. I wonder if you could make a video concerning the sizes / break points for different screens, there is so much information on the net, yet non of it is consistent and gets very confusing. Happy New Year and stay safe.

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

    Thanks for make this awesome video🔥🔥

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

    great point thank you Kevin !

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

    Thnks a lot for this, ur the best!

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

    This tutorial is helpful ❤

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

    Another great one

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

    really nice video, i like ur content, we all need this to be better

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

    El primer video que veo en 2022 :D thanks!

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

    Awesome!!! You ROCK!! :)

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

    My favorite developer. 🤗

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

    Mind: Blown 🤯

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

    This is soooooo AWESOME 🤩🤩🤩🤩🤩

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

    To fix the grid on mobile, I usually wrap the display:grid in a min-width: 400px media query so the minmax() function won’t break the design on extra small screens. I won’t use multiple columns on small screens, so display block works just fine.

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

    Excellent thanks

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

    Thank you!

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

    Great lesson, never used it like this before, really thank you Kevin.
    I have one question. What if I have two grids on top of each other, and each one has its own cards within it, how to make the same width for all the cards in the two sets?

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

    man, nowadays is so easy to develop good looking website.. back then when im actively working as web dev, i still remember that designer need to use `table` to create some sort of layout.. then come along `float` that make everything much easier.. `grid` is even easier to use..

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

    Beautiful

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

    Awesome!

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

    @Kevin Powell Hi, love the tutorial, what key combination are you using to select next occurrences? i herd crl+d but when i use the same combination it selects all instances with "card-xyz" not just the

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

      First you need to select the card then keep on hitting ctrl + D to select all card classes

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

    Thanks ❤

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

    this is the layout that I've wanted for my clothing store - because it's got a comic book style and that's the sort of timid approach to anarchy that I am comfortable doing. And it looks so good! But then I also managed to break something, I was putting it all together on a 2560 x 1289 monitor and I started fiddling with the grid size & aspect ratio until it stopped looking bloated, then I uploaded to check it on my ancient oneplus (6 I think) phone, looks great. smaller iPhone 12 looks even better! - but then It gets messed up on the iPad AIR at 820 width because it pulls the card content div 100% on top of the image. I am super scared of fiddling with it any more because on an iPad Pro it looks perfect at both 1024 & 1366. How far do you go for perfection? I wish I was more confident and could hold knowledge the way you do, you make it look so easy!

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

    Great demo. Thanks for creating it!
    One thing I noticed is that you're using an h2 but no h1, which is a bad thing for accessibility, since it breaks the semantic hierarchy of headings.
    If there's only one level of heading on your page, it should always be h1, and you can style that to be whatever size you want.
    If you're assuming that there would be an h1 above the grid on a "real page", then it would be helpful to say so explicitly, so that your viewers don't accidentally pick up practices that harm accessibility.

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

      Kevin has done at least one other video about semantic hierarchy so there's really no need for him to address something that's part of the bigger picture and would take away from what he wants to cover in this particular tutorial.

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

    Love you Kevin 🤗🇧🇩

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

    what would you suggest for styling LOB design using component based frameworks like Blazor, Angular, VUE etc. ?

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

    I've gone brain dead. In a responsive grid with an odd numbered equal sized "cards" or divs, when the screen begins to get smaller and the cards shift to a new row how can you make that or those cards become centered rather than justified left? Thanks in advance. Great video. I've learned a great deal from you.

  • @user-cp5rd1pp3j
    @user-cp5rd1pp3j 2 года назад

    You said you're moving from BEM. What naming system do you prefer now? Sorry, I'm not an old viewer. And btw, amazing video!

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

    Grazie.

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

    Thanks!

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

      Thanks so much Philip!

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

      Whoa! Awesome, Philip, thank you from the whole community :)

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

    I’m not a mathematician, and this could be a happy coincidence, but in regards to the 1.25 aspect ratio on the feature card image - because the card is spanning the height of two cards, and the card aspect ratio is 1.5, I believe to calculate the correct aspect ratio would be the difference (0.5) to the power of the span (2).
    So (0.5)^2 would be 0.25, which is what you’ve put.
    I’m on mobile and haven’t tested this yet with other sizes, so I have no idea if this theory holds up lol.

    • @The-Dev-Ninja
      @The-Dev-Ninja 2 года назад

      what span mean in aspect ratio or grid? is the font-size?

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

      @@The-Dev-Ninja I was referring to the grid column and grid row span

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

      @@LunaFolf
      I did that maths kind of in the other way around. Since the big card takes up 2 columns, the aspect ratio is essentially is two units of length (let's call them fr as it's kind of similar), while the smaller cards is one unit of width. That gives us: 2fr*1.25 = 2.5fr
      and 1.5fr + 1fr = 2.5fr
      So 2fr * 1.25 = 2.5fr = 1.5fr + 1fr

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

    Is there some way in just CSS to take a random assortment of different aspect ratio image and realign them so that they are properly spaced apart with no dead space? Like take 4 square images and one tall image and having the tall image automatically span 2 rows height creating an even layout? Hard to explain in text.

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

    What keyboard are you using? Thanks for teaching us CSS!

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

    *firebrick* is the color of the month 🎅

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

    Grid area's is my thing now

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

      ok learnt you can declare both grid-template-columns and grid-template-rows at the same time, cool
      Get both rows and columns setup gives more grid-area control, cool

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

    One way to fix the issue with grid-template-columns breaking the layout at small sizes it to use for e.g:
    minmax( min(15rem, 100%), 1fr )
    This way the minimum column size won't overflow even att screen sizes smaller than 15rem.

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

    I'm a big fan of your tutorials and I like the way you handle css, but I get a little frustrated about semantic.
    For instance, when you create a card, shouldn't you be using figure, img and figcaption ?
    I think it'd be more efficient as far as accessibility is concerned, am I wrong ?

  • @bluesky-vc3tk
    @bluesky-vc3tk Год назад

    hello kevin im a beginner in this field when i saw the predefined ccs rules im really confused because there are alot of things i dont know and didnt use

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

    Thank you for the awesome videos. I am working to create a bookmark manager and also a note-taking web app. Do we have any videos on how to fill a form and get that to display on my web app? Thanks

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

    thx

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

    damn! I have to remember all that ...

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

    Hahaha the laugh after the magic numbers, he knows

  • @jamisonr
    @jamisonr 8 месяцев назад

    Around @29:20, you talk about using "em" in media queries and it was because of specific behavior in Safari that "could be fixed soon", but I notice in more recent videos, you still use em. I'm curious if Safari didn't fix the issue, or they did and there are other reasons to still use em in media queries? Perhaps just habit and preference?

    • @KevinPowell
      @KevinPowell  8 месяцев назад +1

      Now it's just habit, Safari fixed it one or two versions ago 😊

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

    Hi Kevin, could you please make a video about Tailwind? Seen many positive comments + approach combining it with PostCSS (supposedly to help with the "class mess" / to create semantic classes. Also what are the pros and contras compared to e.g. SCSS. 🙏

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

      I'm not a big fan of Tailwind, so no plans for content on it 🙂

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

      @@KevinPowell You also could trash it haha. Just to get an idea of how it compares. Some of us hear about it constantly and don't know it so it would be interesting. But totally fine if you don't!

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

    I liked the video, it is very useful. Is there a video that explains the units of measurement in css like rem px.........

    • @KevinPowell
      @KevinPowell  2 года назад +2

      ruclips.net/video/N5wpD9Ov_To/видео.html 😁

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

      @@KevinPowell Thank you 😁😁😁😁😁😁

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

    great course
    i sometimes when i use grids and creat a cards layout i ancounter a card that dont have a picture and that ruins the overall style of cards
    is there a way to make the text and button maybe to be always at the bottom regardless if the card have a picture or not

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

      With this approach that would happen, with how I've set up the alignment of the content.

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

      @@KevinPowell i ll try it on my project thanks for the great content

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

    Does repeat(auto-fit,minmax(15rem, 1fr)); removes necessity for @media (min-width:...) ?

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

      For some layouts, it sure does :). We still need media queries, but not as much as we used to.

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

    That is some of the best most amazing CSS I've ever seen!! Too bad I can't use any of it since I'm learning to code for emails.

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

      Tell us more of the fascinating details of your life.

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

    Is there a way to use grid-template-columns auto-fit with a px min value and a max amount of columns? Say I wanna push columns to the next row if they don't fit but I don't wanna have more than 4 columns (even if a fifth one fits)

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

      using minmax(100px,25%) with GAP makes the last column NOT to fit (and leaving a weird empty space)

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

      No way to limit the total columns, other than limiting the width of the grid container.

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

      @@KevinPowell I actually figured it out!
      This is what I did:
      .grid{
      --gap: 20px;
      --max-cols: 4;
      --min-col-width: 150px;
      --grid-cols-min: max( var(--min-col-width) , calc( (100% / var(--max-cols) ) - (var(--gap) * (var(--max-cols) - 1) / var(--max-cols) ) ) ); //explanation below
      display:grid;
      gap: var(--gap);
      grid-template-columns: repeat(auto-fill, minmax( var(--grid-cols-min,0), 1fr ) );
      }
      //explanation
      max( var(--min-col-width), calc( 100% / var(--max-cols) );
      //this would have been enough if it wasn't because of the GAP. That's why I needed the other part.
      //if I have 4 columns, that means I have 3 gaps, and thats what the calc() does.

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

    why would you put container in rem values?

  • @7doors847
    @7doors847 2 года назад

    Nice shirt!!!!

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

    (?) You know difference between
    { padding-inline-start and padding-left }
    hard to find difference maybe related to { writing-mode } can you help a little

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

    Idk why but watching this whole video was Oddly Satisfying...

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

    Grid isn't supported in ie10 and 11 though? How can we cater for these browsers?

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

    What does API by day, IPA by night mean? Just curious.

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

      APIs are used in development, and IPAs are a type of beer 🙂

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

      @@KevinPowell 😂😂😂

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

    22:41 card featured