Container Queries are going to change how we make layouts

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ค. 2024
  • While media queries that look at the viewport size can be useful, today’s web is very component-based, and having to rely on the size of the viewport is pretty limiting. Luckily, container queries are now a thing!
    🔗 Links
    ✅ Browser support for container queries: caniuse.com/?search=container...
    ✅ New media query syntax support (look for range syntax in the chart): developer.mozilla.org/en-US/d...
    ⌚ Timestamps
    00:00 - Introduction
    00:43 - The very basics
    05:53 - A more real-world example
    10:08 - The range syntax
    11:13 - Named containers
    14:37 - Container-type: size
    17:46 - Container queries with flexbox and grid
    #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 TH-cam 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!

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

  • @zachjensz
    @zachjensz ปีที่แล้ว +73

    I cannot contain my excitement!!! Only thing I dislike is creating markup for flex/grid, we should have container-type: flex; and container-type: grid;

    • @MixbOOsted
      @MixbOOsted ปีที่แล้ว +2

      Whyy TH-cam 👊👊👊

    • @KevinPowell
      @KevinPowell  ปีที่แล้ว +4

      Patron's get my videos 2 days early :)

  • @Defini3
    @Defini3 ปีที่แล้ว +143

    What every website UI/UX designer saves: *Kevins videos*
    I swear every videos of this dude is a gem! These are the videos newbies look for and people with experience will search for when they forgot how to do something.

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

      When I scroll down KPs channel and list of videos, pretty much all of them for the past 2years have been watched all the way through. So grateful!

  • @user-gl6hc1xs3i
    @user-gl6hc1xs3i 11 หลายเดือนก่อน +6

    🎯 Key Takeaways for quick navigation:
    01:10 📏 Container queries focus on component-based layout adaptation within containers, overcoming limitations of viewport-based media queries.
    03:46 🔄 Container queries directly target the nearest container's size, providing more precise responsiveness within components.
    07:46 🔄 Named containers enable applying container queries to specific components, allowing for fine-grained styling based on container context.
    11:15 📐 Using `size` for container type affects both width and height, requiring careful consideration; prefer `inline size` for most cases.
    18:42 📐 Applying container queries within Flexbox or Grid layouts might need additional adjustments due to container behavior; consider the layout structure carefully.
    19:50 🛠️ Container queries can be limited by parent grid dimensions; to target individual grid items, use intermediate div containers as parents.
    21:10 🧩 When working with flex layouts, applying container queries might require adjusting flex properties to prevent children from collapsing to zero width.
    23:18 🧐 Understanding container implications is crucial; they establish new formatting contexts, affect layout behaviors, and eliminate margin collapsing.
    Made with HARPA AI

  • @slava_trushkin
    @slava_trushkin ปีที่แล้ว +21

    Brilliant! This was needed for many years, but better late than never.
    I've hit this wall with media queries almost a decade ago when I was designing themes for forums, where posts can have sidebars, user profile block and so on, so content could be wrapped in multiple layers of stuff, making it impossible to use media queries. My solution was similar to containers, but with JavaScript that toggled classes on container elements. It was a nightmare to maintain. I don't work with forum themes anymore, but PTSD from attempting to design proper responsive themes still remains.

    • @metalstarver642
      @metalstarver642 ปีที่แล้ว

      I had similar problems, and currently use ResizeObserver in JS to set CSS variables to a container to be used in CSS.

    • @summerWTFE
      @summerWTFE ปีที่แล้ว

      Yeah. I guess humanity has finally reached a state of technology to make it happen.

  • @igordasunddas3377
    @igordasunddas3377 ปีที่แล้ว +2

    I honestly enjoy your videos a lot. I love discovering new stuff with someone as bespoken as you.

  • @cedrictheveneau9141
    @cedrictheveneau9141 ปีที่แล้ว +13

    I swear Kevin’s channel is a goldmine, it’s just so nice to know I have just one channel to follow to keep up with CSS evolution; thank you for your hard work Kevin !

  • @archer201977
    @archer201977 ปีที่แล้ว +2

    The ".super-simple-example" class made me laugh in a good funny way, don't get me wrong i learn many new things from you, even at 16 years in my career there are many things i still don't know yet and some i have forgotten. Thanks to you!

  • @robertwattner
    @robertwattner ปีที่แล้ว +10

    I feel like I'm going to be using this A LOT! You're awesome Kevin!

    • @mandokir
      @mandokir ปีที่แล้ว +1

      In 5 years.

  • @georgesaitdev
    @georgesaitdev ปีที่แล้ว +2

    Absolute gamechanger feature! You, mr Powell, are a true legend! Especially these days where every job opportunity screams for React, Vue or Angular, a true frontend spec named CSS is becoming more and more overlooked whilst there is so many development in there. To me personally you really succeeded in your mission keeping CSS fun. Thanks, much much appreciated. 🙌

  • @k1mpman
    @k1mpman ปีที่แล้ว

    Been learning react for a week or two now and I just couldn't find mentions of how people use a component multiple times with different stylings. This solves so much of that for me and it's such a relief that you even mention this in the video because I was going crazy. I ended up thinking most people just use tailwind or something and use the medium, small and large media query for everything. What an amazing video, Kevin.

  • @davidkonevky7372
    @davidkonevky7372 ปีที่แล้ว +3

    I love your videos because css is so overlooked in the web developer landscape and honestly I think it can become the most fun part of the process if you know how to have fun with it

  • @glenn_myridia
    @glenn_myridia ปีที่แล้ว +13

    Kevin, thanks for the great work and keeping us up to date with the latest CSS features. As a front end developer there is always so much new stuff to keep track of, and having a single reliable place like this to keep up to date with CSS is extremely valuable!

  • @MegaClockworkDoc
    @MegaClockworkDoc ปีที่แล้ว +1

    Container queries are amazing, but wait, there's more!🎉🎉🎉
    Wonderful content, thank you Kevin!

  • @rodbrowning
    @rodbrowning ปีที่แล้ว

    I would like to say sorry for tell you that your videos wasn't good because was too long. I was passing through some problems at the time and I still do but now I know that I was the problem not you. Your content are great. Please keep helping people.

  • @helw7
    @helw7 ปีที่แล้ว +1

    🧡🧡 I love container queries 😊🧡 ..
    have been waiting for it for years!
    .. I already implemented it in my free wp plugin (Block Designer) .. actually a polyfill because of browser support 😏 .. I’m so happy this is finally coming! 🥳

  • @LePhenixGD
    @LePhenixGD ปีที่แล้ว +29

    Hey Kevin, I have a suggestion for your next video, a video about all the important CSS media queries (screen, print, orientation, prefers-color-scheme…)!
    For the time being, awesome video mate!

    • @KevinPowell
      @KevinPowell  ปีที่แล้ว +33

      been planning a media query deep dive for awhile, I should probably get around to actually making it!

    • @love.ly.
      @love.ly. ปีที่แล้ว

      Yesss

    • @tworsfeline2302
      @tworsfeline2302 ปีที่แล้ว

      @@love.ly. Why did my TH-cam app translate your comment to have one more "s" when I clicked "Translate to English"? (I am not actually asking you, it's just strange that it happened)

  • @steveportas7961
    @steveportas7961 ปีที่แล้ว

    Amazing!! Can not wait to back this into my daily builds!

  • @Furki4_4
    @Furki4_4 ปีที่แล้ว +1

    The container query and especially range syntax is awesome. I don't think container queries undermine media queries, however they let us to add more complexity which helps websites to be more flexible and responsive ! Thank you Kevin, I can't leave watching your videos everyday for a week ! I... I guess I fell in love with css as a backend developer 🤭

  • @BlojaCastro
    @BlojaCastro ปีที่แล้ว +1

    DAYUMN, next step, editing videos and 3D in minutes

  • @zxamy01
    @zxamy01 ปีที่แล้ว

    thank you for the detailed guide, it helped me install this soft

  • @D7460N
    @D7460N ปีที่แล้ว

    Straight forward and very helpful. Thank you!

  • @nro337
    @nro337 ปีที่แล้ว

    The hero we always need. Thank you!

  • @Pilosofia
    @Pilosofia ปีที่แล้ว

    I never heard about container query before but now I will start using it heavily.

  • @evamotto9276
    @evamotto9276 ปีที่แล้ว

    This is sorely needed, I'm about to research browser support 🤞

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

    I just sometimes get back to these videos to get the full picture again. Thanks Kevin.

  • @TheZyruks
    @TheZyruks ปีที่แล้ว

    This is super cool, hope this get supported by every browser really fast.

  • @EricMuranoAU
    @EricMuranoAU ปีที่แล้ว

    I've been waiting for this for like 5 years!

  • @leangengaleadsit7299
    @leangengaleadsit7299 ปีที่แล้ว

    Thank you Mike! I'm just starting out and tNice tutorials video really helped get the basics down!

  • @haousixridei5137
    @haousixridei5137 ปีที่แล้ว

    cam on ad da co nhung bai giang huu ich cho moi nguoi chuc ad luon thanh cong trong moi viec

  • @GauravKumar-ue7nz
    @GauravKumar-ue7nz ปีที่แล้ว

    Quality of Content and Quality of Production is Top-Notch

  • @mohammedalhashamy6276
    @mohammedalhashamy6276 ปีที่แล้ว

    Hi Kevin! Thanks FOR THIS SERIOUSLY!

  • @vivekkumar-pc1xy
    @vivekkumar-pc1xy ปีที่แล้ว

    Awesome lecture. Thank you so much 🤯

  • @peteremad5228
    @peteremad5228 ปีที่แล้ว

    amazing explanation simple and easy ..cover all used cases ...thank you

  • @noskillzdad5504
    @noskillzdad5504 ปีที่แล้ว

    Awesome content! Thanks for sharing.

  • @chrisevans5787
    @chrisevans5787 ปีที่แล้ว

    i love your videos, thanks for showing a newb like me awesome stuff!

  • @obelisk.5890
    @obelisk.5890 ปีที่แล้ว

    I’m deeply and madly in love with css thanks to Kevin.

  • @msalam4248
    @msalam4248 ปีที่แล้ว

    you are a very good instructor kevin....

  • @josephajibodu2377
    @josephajibodu2377 ปีที่แล้ว

    This is amazing

  • @bibianomauro
    @bibianomauro ปีที่แล้ว

    this is amazing

  • @dArKoMeGa89
    @dArKoMeGa89 ปีที่แล้ว +2

    We've gone from:
    Use more divs than you need to style.
    To:
    Use div just for markup, use CSS to style the page.
    To: now we need more divs again, forgot what we said about using HTML for semantic.

  • @felixenghofer4616
    @felixenghofer4616 ปีที่แล้ว

    Thank you so much for that video, Kevin - so well explained as always! I really needed exactly this behavior in the past and was wondering why container queries don't exist. Finally! 🙂

  • @muck2000
    @muck2000 ปีที่แล้ว

    WORKING thx bro

  • @charliecoplestone9694
    @charliecoplestone9694 ปีที่แล้ว

    Genuinely game-changing.

  • @henriqueaguiar9737
    @henriqueaguiar9737 ปีที่แล้ว +33

    Hey, Kevin! Do you plan on doing some content on image optimization and how to get your images ready to be used on websites? Thanks in advance and keep up the great work!

    • @estherjonathan_
      @estherjonathan_ ปีที่แล้ว +1

      Really Help..
      Kevin pls can you help on this

    • @eggkookoo
      @eggkookoo ปีที่แล้ว +4

      This strikes me as vaguely scam-ish.

    • @Brechtvdh
      @Brechtvdh ปีที่แล้ว +1

      @@eggkookoo One can only try... 😂

    • @eggkookoo
      @eggkookoo ปีที่แล้ว +2

      @@Brechtvdh I mean the "helpline" message stuff.

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

    Beautiful

  • @sajjadkazemi
    @sajjadkazemi ปีที่แล้ว

    thabk you for this video I really neded it♥️

  • @MixbOOsted
    @MixbOOsted ปีที่แล้ว +2

    Here is a Unique content
    Css 💫 kevin
    Nice 👍👍👍

  • @nerds6205
    @nerds6205 ปีที่แล้ว

    My inspiration 🤩

  • @QwDragon
    @QwDragon ปีที่แล้ว +4

    Actually { container-type: size; height: 100%; overflow: auto; } seems very usefull.
    And it's a bit strange there's no container-type: block-size yet.

    • @KevinPowell
      @KevinPowell  ปีที่แล้ว +3

      block-size and some others should come eventually :)
      The issue with `height: 100%` is we don't always want that either though. But yes, it could be pretty useful in the right situation. In my video where I look at container units coming later this week, I found a few better use cases for dealing with heights :)

  • @dopetag
    @dopetag ปีที่แล้ว

    @container is the future for responsive typography

  • @pXnEmerica
    @pXnEmerica ปีที่แล้ว

    I dunno how you can smile and look at CSS at the same time, lol.

  • @fcfc
    @fcfc ปีที่แล้ว

    all those years of frustration... i wish i had this back then!

  • @larmiekeys7338
    @larmiekeys7338 ปีที่แล้ว

    Really work

  • @octothorpe12
    @octothorpe12 ปีที่แล้ว

    this is gonna take me awhile to wrap my head around.

  • @The-Dev-Ninja
    @The-Dev-Ninja ปีที่แล้ว +1

    mind-blowing

  • @Morrile1
    @Morrile1 ปีที่แล้ว +1

    Improved control is certainly on it's way, and about time too!

  • @27sosite73
    @27sosite73 7 หลายเดือนก่อน

    ty mate

  • @chazy123
    @chazy123 ปีที่แล้ว

    Those extra classless divs near the end, I really felt that.

  • @kevbonett
    @kevbonett ปีที่แล้ว

    Great explanation! However, I'm a little disappointed that we have to add a bit of div-itis when using flex/grid. Having said that, it's a small price to pay for all this extra goodness. 😁

  • @sovereignlivingsoul
    @sovereignlivingsoul ปีที่แล้ว

    excellent video, a problem solver i hope.

  • @mlookmero1004
    @mlookmero1004 ปีที่แล้ว

    concepts finally line up in my brain and...well, who knows? Maybe I'll be able to make sotNice tutorialng now.

  • @drizzbot2994
    @drizzbot2994 ปีที่แล้ว

    Best of the best

  • @27sosite73
    @27sosite73 7 หลายเดือนก่อน

    this guy loves css

  • @jeffkinley3698
    @jeffkinley3698 ปีที่แล้ว +2

    Hi Kevin. Great demo. I was trying to create a demo of container queries to explain this concept to my colleagues. I used this as a basis for my demo. Also, just curious why you chose to use data attributes for the sizes and not just a classes. Any particular reason?

  • @SoulStitch1111
    @SoulStitch1111 ปีที่แล้ว

    sadly, this only made me more confused. A little all over the place. Will have to watch it a third time and slow it down. Thank you for all you do.

  • @mohibuddinahmedumer4738
    @mohibuddinahmedumer4738 ปีที่แล้ว

    it work on my pc thx bro vеry much

  • @StephenRayner
    @StephenRayner ปีที่แล้ว

    Very cool

  • @r-i-ch
    @r-i-ch ปีที่แล้ว +1

    This is great! Do you have a codepen for it? (I can see a lot, but not the base styles)

  • @wfl-junior
    @wfl-junior ปีที่แล้ว

    next gen css is going to be bonkers

  • @thangluong2365
    @thangluong2365 ปีที่แล้ว

    I am coming from soft one 4.6 and I am so torn with soft soft. It seems great as it is so in-depth in its' capabilities but, so fiddly to get

  • @olisaemekaaghabuilo8688
    @olisaemekaaghabuilo8688 ปีที่แล้ว

    Kelvin this is Awesome...............

  • @joshmeurer4956
    @joshmeurer4956 ปีที่แล้ว +1

    I noticed recently that adding container-type to the class of an element seems to be making it z-order on top of an element that is positioned absolute via javascript. I wonder if you have any observations of whether this is expected and if you have any suggestions for how to plan for or manage this?

  • @zxuiji
    @zxuiji ปีที่แล้ว

    4:38, while not as convenient as containers you can achieve the same with media queries, if you can do it with old css then you should, then you won't have stubborn mules who use the old **** complaining at you.

  • @mohitkamal8124
    @mohitkamal8124 ปีที่แล้ว

    Good video

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

    It's frustrating to me, but when doing @container (width < 940px), the width it uses is the width of the content box of the element and does not include padding. When padding is applied, it will actually apply the styles when the element (including padding) is less than 957px (padding left and right is 8px). So the only option I see is to modify my container query to take into account the applied padding, which is not great readable code. And if I ever decide I need to change the padding of my container for whatever reason, I'll need to update the query to account for it.
    Changing the box-sizing property of the container does nothing to change this behavior. It always in relation to the width of the content-box of the container. Frustrating.

  • @superalexturbo
    @superalexturbo ปีที่แล้ว +1

    The real problem for now is Firefox. They have to solve a bug and when they will release the fix we could finally develop with container queries

  • @anth0ni33
    @anth0ni33 ปีที่แล้ว

    When this was showcase for the first time I literally danced for joy

  • @krateskim4169
    @krateskim4169 ปีที่แล้ว

    awesome

  • @codebycarlos
    @codebycarlos ปีที่แล้ว +1

    Hi Kevin, awesome video as always thank you! I was curious as to why you used the data-type attribute to set the container stylings in the beginning. Would it not be more appropriate to have these as classes?

    • @KevinPowell
      @KevinPowell  ปีที่แล้ว +1

      More common, yes, but no reason it's more or less appropriate. I've taken that idea from CUBE CSS, and personally I find I like it a lot, using data-attributes as modifiers instead of classes. As long as you have a consistent system, either approach is fine :)

  • @friesnsoda1916
    @friesnsoda1916 ปีที่แล้ว

    Yossshaaaa let's go!!

  • @timseguine2
    @timseguine2 ปีที่แล้ว

    Is there some kind of preprocessor or polyfill for this feature to make it more accessible? Kind of neat, but I don't really find it that useful as is as long as it is not supported in firefox.

  • @macx
    @macx ปีที่แล้ว +1

    Thanks for sharing this! You become my number one resource for new features, I don't care about the sites you are looking for. ;-) Anyway, working as a front-end for more than 23 years and also being a lecturer for students, this video was hard to follow. It's not because of the new stuff, it's because of your preparations upfront. Without knowing your code, I can't judge what the outcome will be. My suggestions: Build simple markup in the video as well. Using Sass and it's grouping could also help. I have to try it myself this time to understand it completely. And this is different for your other videos.

  • @luispato9335
    @luispato9335 ปีที่แล้ว +1

    Really excited for the container queries, but i am quite sad the the element itself (the container) cannot be styles in the container query, which will make us write unnecessary markup. Such a turn down...

  • @michalnowak2181
    @michalnowak2181 ปีที่แล้ว

    thx

  • @GHOST8799
    @GHOST8799 ปีที่แล้ว

    Do container queries have an influence on the formatting context? Ie/ do they get rid of collapsing margins?

  • @malignate4sd
    @malignate4sd ปีที่แล้ว

    I have used this principle a lot with resizeobservers, but builtin in css is oviously better and more flexible.

  • @dimitrist.8855
    @dimitrist.8855 ปีที่แล้ว

    What plugin do you use in vscode for auto indentation after saving?????

  • @TufanCalisir
    @TufanCalisir ปีที่แล้ว

    Hello, is it possible to get the .html and .css code to dive more in depth with the container queries? Like in codepen or so?

  • @arshad1781
    @arshad1781 ปีที่แล้ว

    nice

  • @alanbloom20
    @alanbloom20 ปีที่แล้ว

    @container (excitement >= 100%){
    .celebrate{
    display: absolutely 💯
    }
    }

  • @gonzalowilliams
    @gonzalowilliams ปีที่แล้ว

    How do you show a line connecting tags in the editor? I couldn't find a plugin that works with HTML. It works only with js and css

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

    GAME CHANGER feature right there, and I’m so glad browser support is very good for this one right now.
    One thing that came to my mind, specially to avoid dealing with the grid/flexbox issue you pointed out: if you’re breaking your UI up into components, doesn’t it make more sense to make the component’s container itself into a container (that would be .call-to-action in your example)?

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

      just wondering did you figure out the answer to this question? I want to know as well

  • @mrrolandlawrence
    @mrrolandlawrence ปีที่แล้ว

    this could be awesome for items in a gallery... set the background to display an image depending on the container size, not the viewport width. esp if the number of photos in the gallery changes on the width of the grid say.

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

    14:05 I wonder how hard would it be to make the inline-size the first property instead of the second, hence allowing us to use it as a shorthand property without needing to declare both values...

  • @Andres_cali
    @Andres_cali ปีที่แล้ว

    Uyyyy!!!! No lo puedo creer! De esta manera me enamoro mas de usar lenguajes puros y no react.

  • @filippotinnirello
    @filippotinnirello ปีที่แล้ว

    8:35 couldn't you assign the container-type directly to aside and article? since container doesn't change anything per se, you could let it be the default behavior for these tags, isn't it?

  • @theseangle
    @theseangle ปีที่แล้ว +1

    42% support on caniuse :(
    Why don't browsers use dynamic engines which can Fetch features from a server whenever a spec update happens. That way a soft/mini/cloud update happens on all browser versions, meaning even browsers from 5 years ago can have most of 1 month old features

  • @adeisaac
    @adeisaac ปีที่แล้ว

    😀😀😀 banger.....

  • @louroboros
    @louroboros ปีที่แล้ว

    Regarding the 3-card grid layout: Why not set .even-columns > .call-to-action { container-type: inline-size; } ?

  • @user-gn8hj2cc6c
    @user-gn8hj2cc6c ปีที่แล้ว

    02:29 what extension do you use to show html code on css file?

    • @KevinPowell
      @KevinPowell  ปีที่แล้ว

      Pretty sure that's built into VS Code? Just select and hover.