Masonry layout with CSS only!

Поделиться
HTML-код
  • Опубликовано: 11 июл 2024
  • The first 1000 people to use the link will get a free trial of Skillshare Premium Membership: skl.sh/kevinpowell12201
    Masonry Layouts have been around forever now, and considering that they are surprisingly hard to actually implement. Well, not so much now that they are coming to CSS at last! It's still in the very early stages, only working in Firefox Nighty as I upload this, but it's in the works and hopefully, we don't have to wait too long before it becomes widely supported.
    Because it does have poor browser support, I also take a look at a possible fallback using CSS Columns as well 😊.
    Codepen: codepen.io/kevinpowell/pen/yL...
    /// Timestamps
    00:00 - intro
    01:07 - basics of masonry
    05:17 - using spans
    06:55 - align-tracks
    08:45 - creating a fallback
    13:18 - making it more robust
    15:38 - outro
    This video was sponsored by Skillshare
    --
    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
    ---
    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.
    Instagram: / kevinpowell.co
    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!

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

  • @tonyblox
    @tonyblox Год назад +54

    2 years later, support is the same. For anyone wondering can they use this: no, you can't.
    grid-template-rows: masonry is STILL only supported as an experimental feature in firefox that you have to enable first.

    • @DylRicho
      @DylRicho Год назад +3

      This is so infuriating.

    • @peterwise
      @peterwise 10 месяцев назад +2

      However, you can use the display: columns fallback that he outlines...

    • @magoxxii
      @magoxxii 7 месяцев назад +1

      still same

    • @ReactWithSamwize
      @ReactWithSamwize 2 месяца назад

      It still doesn't work today, such a joy killer

  • @smohammadhn
    @smohammadhn 3 месяца назад +13

    2024 and still 0% availability ...

  • @ViorelMocanu
    @ViorelMocanu 3 года назад +53

    CSS Grid with Flexbox finally feels like design as it was meant to be implemented in code form, thank God we're not relying on floats or tables anymore! :)

  • @nimrodnorway3023
    @nimrodnorway3023 3 года назад +4

    Everytime I watch a video of yours I am reminded of the wholesomeness of your channel and the content you produce. It's just so nicely and concisely presented.

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

    I was just thinking about this kind of layout a couple days ago. Thanks for posting. Hopefilly it'll get broader support sooner than later.

  • @Allformyequine
    @Allformyequine 3 года назад +13

    Been loving grid and flexbox... changed everything! That's what is exciting to me! So much less markup!

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

    Ya know what else is awesome: Kevin Powell! Thanks bro for another helpful vid.

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

    Great work, Kev. Many thanks.

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

    grid-template-row: masonry ? Mind blowing. Awesome, Kevin!

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

    Love it! Love iiiiiiiiiiiiT! :D Thanks Kevin!

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

    Holy Hannah! This is such a timesaver. Looking forward to future support in other browsers.

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

    This was extremely helpful! Thanks a lot!

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

    Thats an amazing technique that I also use on my css also, but I loved the way you explained it!

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

    Wow this is great 😍

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

    Even the column solution is wonderful!

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

    Another great video
    Thnx Kevin, you're the best 🙏

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

    Thanks Kevin. You are great.

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

    It's working. Thanks a lot. Subscribed. 👍

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

    Awesome,also currently enjoying your scrimba course 😀😀😀

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

    Awesome !

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

    great video - thanks!

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

    Great! Thank You!

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

    Great work sir, this video helps me to make a dynamic gallery page. Thank you..

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

    Thank you so much ❤️

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

    Many Many Thanks !!!

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

    Playing with backdrop-filter lately - lots of fun

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

    Thanks for the tutorial

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

    Thank you so much sir.

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

    you're a life saver

  • @StephenMoreira
    @StephenMoreira 3 года назад +4

    Magic. I remember the struggles trying to get this done without it, sucked hard.

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

    Thank You

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

    Este tutorial é perfeito :)
    Perfect tutorial :)

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

    Kevin our CSS god.

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

    This is amazing!!! I love masonry layouts and include them in almost all my projects, this will be a game changer!

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

    Muito obrigada pelo seu vídeo, me ajudou muito.

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

    Took this and made `--gap` and `--columns` responsive! Works like a charm. The only thing I still need to figure out is how the hell to deal with edge cases where images in the masonry are not balanced according to width and height, even tho, they could be!

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

    Still no browser support 😭

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

    I like how you can apply image affects straight in css, only for background images I think

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

    That's why I like you! 💚💙❤️🔥

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

    You can only use the column property if you have a finite number of cards if you don't the layout is gonna be changing continuously. And the common use of masonry layout is in some kind of news site.

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

    Ive been waiting for this. On one of my sites I use columns:5; which is not ideal because it aligns content from top to bottom instead of left to right. I can't wait for it to become more mainstream (in about 5 years ugh, that's the downside of web development)

  • @techtipsuk
    @techtipsuk 3 года назад +4

    I've just done this on a charity site and I had to use css columns. Works well enough but you can't span properly and drop shadows cause issues. You can get around this by using CSS filter drop shadow with a wrapper around every child in the masonry and then applying padding to each wrapper. You need to do this as the shadows get clipped otherwise. I'll do a video as this took me several days of messing around to work out.

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

      I've used columns at work and it works on chrome but breaks on FireFox so after watching this I'm considering converting it to grid.

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

      @@nathanaelsmith3553 yeah but browser support is none existent at the moment. When it only works in Firefox nightly that is not a workable solution right now. I’ve actually found Firefox the most reliable browser with columns it views my site perfectly and was the only browser that did.

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

      @@techtipsuk I mean vanilla grid - not this new feature of grid

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

    Nice just started watching you im lacking in css :P

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

    Wow. Thought I knew grid but had never heard of align-tracks or the masonry value

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

    Nice vid. Have you made a tutorial for masonry layout with JS?

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

    It's really amazing. This tutorial solved my problem very quickly.
    But grid-template-rows don't work. same as align-tracks. Can you give me an idea about them (align-tracks, grid-template-rows), please?
    Thanks @Kevin

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

    grid-template-rows: masonry; not working for me, both on Safari and Chrome (on Mac, last update done).
    Am I doing something wrong or it's the browser support?

  • @AM-rb4ps
    @AM-rb4ps 3 года назад +1

    anyone else noticing that the "featured" class doesn't work in his example code (on codepen) when using masonry?
    (but it does when grid-template-rows: masonry; is turned off)

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

    Almost a year has passed and nothing of support for this feature :/

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

    Looks awesome, can't wait until it's released bug(s) free

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

      OK, I should have viewed it completely before commenting.....

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

    cool

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

    What's interesting is that display: column was not supported when I was testing this on Live Server / Chrome on my Local PC. Will search for column videos now to see if there's something I am missing.

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

    Love u sir. Next video should be on Glassmorphism

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

      Great idea, though I have a few in the pipeline already so it might be a little bit

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

      @@KevinPowell ok sir. Thanks a lot for such a good content

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

    The first 1000 people to use the link will get a free trial of Skillshare Premium Membership: skl.sh/kevinpowell12201
    I had a big brain fart on this one with the columns. As CK002 kindly pointed out, there is no such thing as display: columns. It's invalid and literally does nothing at all. Just throw a `columns: 3` or whatever you need on there are you're good to go.

  • @snowandcoal
    @snowandcoal 7 месяцев назад +1

    Still no browser support in December 2023. Does anyone know why?

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

    not working in chrome or any other browser and column property will not work with overflow-x auto if i want to make it scroll with limited height.

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

    My God ...😮😮

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

    "display: column" is not supported by chrome, is it like it was supported 2yrs ago and not now?

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

    @Kevin is there a better way now with flex or gird?

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

    Interesting idea, would this work for a blog to display in date order, top to bottom and left to right?

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

      It would, yup!

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

      @@KevinPowell haha just read it back got that the wrong way round, doh, should have said left to right and then top to bottom, so in rows. Going to have to have a play with this and see what is possible, thanks Kevin

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

    grid-template-rows: masonry showing invalid property

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

    Hi Kevin Powell i need for your help. How can i contact?

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

    watching you, makes me feel anything is possible with css, love from india!!!!

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

    grid-template-rows: masonry; is not working

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

    Does this work in other explolers for now? Like, does it work for Chrome, Safari, Edge, Opera etc.?

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

      Not yet, it's still something that's being worked on. It might be awhile, as it's part of the level 3 specification of grid. level 2 is subgrid and there isn't much movement on that yet either.

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

      @@KevinPowell Thank you sir

  •  Год назад +1

    Great video! It is still not supported by Chrome... shame...

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

    will be cool to use in 2030 when we have to built 3d hologram layouts~

  • @ck0024
    @ck0024 3 года назад +4

    *display: column;* is an invalid property.

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

      Talk about a brain fart on my side there! You just need to put in columns: and how many you want. Thanks for mentioning it, I'll pin a comment to the top.

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

    3 Years Later: For anyone wondering if they can use this, the answer is no, you can't.
    grid-template-rows: masonry is STILL only supported as an experimental feature in firefox that you have to enable first.

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

    Can you do a video about background position?

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

      I have it on my todo list :)

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

    Hi. When This will be capatible with all browsers?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +3

      ...it only took Chrome and Safari 4 years to gain support for subgrid... so, another 4 years? 😭 - Honestly, no idea, and now that they all support subgrid hopefully we see them start to work on this, since it's the next level in the grid spec, but I'm not holding my breath.

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

      @@KevinPowell I have a php image download website where I want to use masonry layout. Currenly, I am using css column property. It looks like masonry but not exactly from row perspective... Please suggest me the best possible way...

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

    why not use columns: 3; > div { break-inside: avoid } That also works masonry. Not as cool as grid but in 2022 the masonry attr still not availble in browsers

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

    grid-template-rows: masonry; is not working. Why?

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

    I never understand why we can not have units of measurement on % related to the parent conteiner, similar as we have "vw" and "vh" with respect the viewscreen. It would make everything much easier.
    I hear that it would be impossible to set because the parent can not be defined? or something like that.. Why not? You just need a well defined parent, and from that you get your chain of units one derivative from the other.
    Also.. if this can be done in javascript, why browsers can not do it as well?

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

      You can use % for that though? like, width: 50% would be 50% of the width of it's parent container...

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

      ​@@KevinPowell No I cant.. because if I want to set the width to 100% of the parent width and a height of 50% of the parent width (to keep certain ratio), then I cant.
      Instead with "vw" and "vh" I can do that, I can said width: 100vw and height: 60vw, but we dont have an unit like that with respect to the parent container, only to the viewscreen.
      The same for width: 40vh and height: 20vh for example.
      Having those units, it would make any responsive layout super easy to make.
      In order to achieve similar ratios right now, we have to do weird tricks with the padding.

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

      @@AngelLestat2 they are working on a as aspect-ratio property!

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

      ​@@KevinPowell yeah, I read that. I guess that could be enough, but still surprise that this feature was not implemented before or that I did not see too much people asking for that in all these last years.
      Maybe is tricky to implement without performance issues.

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

      @@KevinPowell aspect-ratio still only has 90% support. Image every 10th person can't use your service

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

    Unfortunately does not work in Safari

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

    I also do videos about programming!😁

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

    still not available in common browsers

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

    Positioning is not possible in GRID? Please guide.

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

      What do you mean?

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

      @@KevinPowell Some divs are arranged by grid. Now I want to place two inside one of those divs. For doing so we have to position those *2 divs.* Is it possible?
      E.g: How can we place inside ?

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

    more easy
    .masonry {
    -moz-column-count: 4;
    -webkit-column-count: 4;
    column-count: 4;
    }

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

    Still only on firefox 🙃

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

    Hy kevin can I get an answer.. Bcz no. One reply me on discord (sadly 😞😤)
    "hi guys,
    i've just watched kevin's last video about masonry layout...
    i see kevin used some css property for chrome fallback..
    ```css
    display:column;
    columns:3;
    ```
    Im curious and try that on my chrome...
    but i got this working property instead...
    ```css
    display: table-column;
    column-count: 4;
    ```
    why is this happening..?
    i got different property...
    note that my chrome latest update...
    thanks"

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

      this is my question link on discord if you prefer to answer there...
      discord.com/channels/436251713830125568/535502841943687179/786435897612435486

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

    Masonry value is still not supported in most browsers

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

    Browsers still has not gained support for it... 0% support in caniuse

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

      It's coming... eventually... we're still waiting on subgrid from most of them, once that lands, they can eventually get started on this :D

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

    And still not implemented huh? :(

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

    Hi

  • @NamLe-sl4qy
    @NamLe-sl4qy Год назад +1

    From document of developer.mozilla, grid-template-rows: masonry - This feature is only implemented in Firefox