CSS Flexbox Tutorial #11 - Grid vs Stacked Layout Example

Поділитися
Вставка
  • Опубліковано 9 лют 2025
  • Yo ninjas, in this CSS Flexbox tutorial, I'll walk through creating a grid and stacked layout, which the user can toggle between.
    ----- COURSE LINKS:
    Source files on GitHub - github.com/iam...
    Brackets editor - brackets.io/
    ---------------------------------------------------------------------------------------------
    You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress & more on the channel homepage...
    SUBSCRIBE TO CHANNEL - / @netninja
    ========== JavaScript for Beginners Playlist ==========
    • JavaScript Tutorials f...
    ============ CSS for Beginners Playlist =============
    • CSS Tutorials For Begi...
    ============== The Net Ninja =====================
    For more front-end development tutorials & to black-belt your coding skills, head over to - / @netninja or thenetninja.co.uk
    ================== Social Links ==================
    Twitter - @TheNetNinja - / thenetninjauk

КОМЕНТАРІ • 72

  • @kakarnyori5457
    @kakarnyori5457 8 років тому +42

    "box-sizing: border-box" was an aha! moment for me! Thanks man.

  • @jsnmad
    @jsnmad 4 роки тому +8

    Your CSS Tutorials are the best online. Love your delivery. You understand how to communicate a thought in a live way (not lousy and rambling). Excellent work.

  • @johnborron1059
    @johnborron1059 2 роки тому +4

    Wow, that escalated quickly. I was going alright up to lesson 10. Challenge accepted though. You are a fantastic teacher.

  • @achuenjoy
    @achuenjoy 7 років тому +12

    All the 12 tutorials are excellent. I got a nice idea on how the flex properties work. Thanks a lot for posting these videos! It is very helpful.

  • @malcolmcolindixon
    @malcolmcolindixon 4 роки тому +6

    Here's the Javascript code to replace the JQuery (apparently shouldn't be used for new projects). A week ago I wouldn't have had a clue how to do this, but by following many of the Grand Master Ninja courses my skills are improving dramatically, wax on wax off!!!
    const stack = document.querySelector("a.stack");
    stack.addEventListener("click", e => {
    const articles = document.querySelectorAll("article");
    articles.forEach(article => article.classList.add("stack"));
    });
    const grid = document.querySelector("a.grid");
    grid.addEventListener("click", e => {
    const articles = document.querySelectorAll("article");
    articles.forEach(article => article.classList.remove("stack"));
    });
    This can also be done using CSS only but needs a few changes to the HTML too.
    Remove the div class="controls".
    Add:
    Layout:
    to the beginning of the
    No need for the tag too, so remove it.
    In the "mobile" CSS add:
    #layout, #layout-label {
    display: none;
    }
    In the CSS add the following in the @media query:
    #layout-label {
    display: block;
    flex: 0 0 100%;
    margin: 20px 0;
    padding: 10px 0;
    background: darkgray;
    text-align: center;
    }
    #layout-label::after {
    content: " Grid"
    }
    #layout:checked ~ #layout-label::after {
    content: " Stack"
    }
    #layout:checked ~ article {
    flex: 0 1 100%;
    }
    No need for any of the .controls CSS so that can be removed.
    It's great trying to get things to work using CSS only if possible IMO.

    • @adis7856
      @adis7856 Рік тому +1

      I was wondering why my script wasn't working :(

    • @kimberlymark2607
      @kimberlymark2607 Рік тому +1

      This was really helpful. That’s a lot. It finally worked thanks to you❤

  • @chibuezevince
    @chibuezevince 2 роки тому

    Happily shouting “wahhh” in the ninja’s voice just as every tutorial is about to start. 😂❤

  • @alan-overthenet
    @alan-overthenet 4 роки тому +2

    This is excellent, thank you. I love the stack and grid bit. A bit of extra styling takes away the Layout: Stack and Grid option on mobile and brings it back on 768px.

    • @kimberlymark2607
      @kimberlymark2607 Рік тому

      What style would do that?

    • @alan-overthenet
      @alan-overthenet Рік тому

      Hello. I can't remember what I did yesterday, never mind 3 years ago. I will try to find it, but don't hold your breath.

  • @ayushkushwaha171
    @ayushkushwaha171 6 років тому +3

    Your videos are pretty awesome dude...Keep up the good work!

  • @victoremmanuel1130
    @victoremmanuel1130 8 місяців тому +1

    Good day Mr shaun, i followed everything you did here, but when i click on grid or stack it changes for a split second then i receive an error message.
    This: Cannot GET /example-3/%C2%A3

  • @zoecarlibur
    @zoecarlibur 8 років тому

    really enjoyed this. straight forward and fast.

  • @AS-zw4lk
    @AS-zw4lk 7 років тому

    luuuurve your tutorials! Always some extra polish! Thanks

  • @markbalazo1914
    @markbalazo1914 6 років тому +1

    Cool example!

  • @ludwighallgren2554
    @ludwighallgren2554 8 років тому

    great tutorials all over. TY man

  • @mohamedyoussef8835
    @mohamedyoussef8835 3 роки тому

    Awesome Tutorials as always +++++++++ thank you 🙂🙂

  • @andrewhowe9800
    @andrewhowe9800 8 років тому

    once again, so helpful. Thanks

  • @tomisinergy4963
    @tomisinergy4963 4 роки тому

    i will start learning jquery next week but it was good tutorial :-)

  • @girlandhercomputer7204
    @girlandhercomputer7204 5 років тому

    wow this is very practical, thank you a ton

  • @sst8872
    @sst8872 6 років тому

    Thank you so much. You're great as ever. Thank you.

  • @harenhallharfoot
    @harenhallharfoot 5 років тому +2

    jquery is too advance for my noob self!! D'x Otherwise love your tutorials! Thank you so much for making them!!

  • @pavlemiovcic4627
    @pavlemiovcic4627 4 роки тому

    Great, so helpful, thank you very much!

  • @konstantinkhomenko7472
    @konstantinkhomenko7472 8 років тому +1

    Can you help, how to be if we have eight blocks in two rows. And when we reduce screen they transform in three rows, and the last row consist just of two blocks on the sides of the screen with a space between them. Thank you

  • @SudipBhattacharyya
    @SudipBhattacharyya 3 роки тому

    Excellent!!! :)

  • @flashboyonly
    @flashboyonly 8 років тому

    Thanks man for all tutoriall you are makeing :) I subscribe today :)

  • @Mustafa-cv1pk
    @Mustafa-cv1pk 5 років тому

    oh damn , that is beautiful thank you

  • @THEMARILAU
    @THEMARILAU 4 роки тому

    How do you make it to be selected in the browser when you go over an element in the editor?

  • @IMKLASH
    @IMKLASH 7 років тому

    Great video - thanks!

  • @fauzikaliki8473
    @fauzikaliki8473 8 років тому

    Thumbs up! What if I want to add image at the top of each articles either stacked or grid? Thanks.

  • @navpallav3631
    @navpallav3631 3 роки тому

    Very nice. thanks

  • @siddhantsharma7239
    @siddhantsharma7239 2 роки тому

    Can anyone tell me what is the problem that i am doing as in my case when i click stack it just happens so quick and go back to grid and i m not able to identify what is the problem
    Please can anyone help me

  • @dejanmarkovic1690
    @dejanmarkovic1690 6 років тому

    Nice tuth bro!

  • @kenshinnanashi9469
    @kenshinnanashi9469 5 років тому

    when im shrinking the browser size the layout doesn't change to stack automaticaly. where's the catch ?

  • @marcomadflow2858
    @marcomadflow2858 8 років тому

    How to I get this to scale down from 3 columns to 2 and then 1? As opposed to scaling from 3 columns to 1?

  • @rameshdahal2842
    @rameshdahal2842 7 років тому +1

    When u have 5 article box. justify-content:space-between; creates huge space between the last two artcle boxes. How to get rid of this issue??

    • @artihlec
      @artihlec 6 років тому +1

      use margin property instead of justify-content

  • @mikhailsamotaev5605
    @mikhailsamotaev5605 5 років тому

    Cool! Thank you!)

  • @rogeclash2631
    @rogeclash2631 7 років тому

    thanks for sharing this

  • @mehreganrahmani6618
    @mehreganrahmani6618 4 роки тому

    Thanks a million, These series are very helpful for me .. I try to watch them all and practice. but one question ( I asked in grid tutorial too, but since then no body answered me and I just couldn't make myself clear to google and find my answer in it :D ) what do you use that specifies the element in browser? I mean, where does that blue border or blue background come from whenever you click on an element tag?.... I Think That is very helpful for someone like me, a Total Beginner.

    • @elpontador9826
      @elpontador9826 4 роки тому +2

      It's from his code editor

    • @mehreganrahmani6618
      @mehreganrahmani6618 4 роки тому

      @@elpontador9826Thanks for your reply, Then I just decided to use brackets instead of VS-Code, because of this feature! seems really cool

  • @vaughantesta2999
    @vaughantesta2999 4 роки тому

    Hey Ninja Master, Quick question, can you tell me what the vscode extension you are using to highlight the section of the browser your in when you click on the section in the vscode side. When you highlight or click on the p tag its highlights it in the browser. Many Thanks Vaughan

    • @Kirisapostle12
      @Kirisapostle12 4 роки тому

      I am pretty sure he is using "Atom" not "VSCode"

    • @onrjs
      @onrjs 4 роки тому

      @@Kirisapostle12 he is using brackets ( brackets.io/) and it has a live server extension

  • @jojo_koomson
    @jojo_koomson 4 роки тому

    the jquery is not working what should i do. This is the error its reading:
    Uncaught TypeError: $(...).removeclass is not a function
    at HTMLAnchorElement. (grid-vs-stack.html:64)
    at HTMLAnchorElement.dispatch (jquery-1.12.1.js:5226)
    at HTMLAnchorElement.elemData.handle (jquery-1.12.1.js:4878)

    • @jojo_koomson
      @jojo_koomson 4 роки тому

      ok found the problem. Sorry!

    • @Niawhax_cracker
      @Niawhax_cracker 7 місяців тому

      ​@@jojo_koomsoncan you pls help me out on my script its not working kept bringing not defined on the console

  • @annmusicworld4016
    @annmusicworld4016 4 роки тому +3

    I got lost on the "jquery" part... like "what? where did we see that?" hehehe, but I got the sintaxis.

  • @Niawhax_cracker
    @Niawhax_cracker 7 місяців тому

    Why is my script not working cam someone pls help me out
    Kept saying not defined

  • @jamiumuritala4892
    @jamiumuritala4892 6 років тому

    If one wants to remove the content of the div(Layout: Stack and grid) when it gets to the mobile view how do one go about it

    • @BolinhoDeArrozCozido
      @BolinhoDeArrozCozido 5 років тому

      use the media query to resize it to 0 or something like that

  • @Ziad-Al
    @Ziad-Al 2 роки тому

    sometimes i have the urge to click Like button many times:)

  • @avengerbolt4908
    @avengerbolt4908 6 років тому

    which plugin you are using to highlight blocks on browser? I mean real time when you are editing on CSS.

    • @jamiumuritala4892
      @jamiumuritala4892 6 років тому

      it's the text-editor life view you can download it at brackets.io

  • @ismetglumcevic7061
    @ismetglumcevic7061 8 років тому

    Hi, how make masonry grid with flex?

  • @rogeclash2631
    @rogeclash2631 7 років тому

    top class

  • @raj080288
    @raj080288 8 років тому

    why are you shrinking them in this case?

  • @princeongata9453
    @princeongata9453 7 років тому

    what text editor is that?

  • @alexyap3659
    @alexyap3659 8 років тому

    does anyone know what plugin he is using to see his changes in real time?

    • @Michal025
      @Michal025 8 років тому +1

      this is an option in Brackets. Just click the horizontal lighning icon in right top corner. Then the Chrome will open with you site.

    • @alexyap3659
      @alexyap3659 8 років тому

      miszka do you know of one for Atom? it's what i am using right now and i kind of prefer it thanks

    • @iulitab
      @iulitab 8 років тому +2

      atom live server plugin -> atom.io/packages/atom-live-server

    • @lardosian
      @lardosian 8 років тому

      Maybe a stupid question but in Atom I do not see an option to launch an html file in the browser. Ie in notepad++ theres is an option to 'launch in browser', thank you.

  • @JohnMervinancheta
    @JohnMervinancheta 4 роки тому

    excellent but i think i need to learn javascript soon

    • @notdaveschannel9843
      @notdaveschannel9843 4 роки тому

      1 piece of advice. Learn JS from the ground up before going anywhere near libraries like jQuery. For years when vanilla JS was a bit crap, people like me ended up sort of learning the 2 in parallel and getting confused.

  • @romtekch4958
    @romtekch4958 4 роки тому

    Why type #fff instead of "white"?

  • @abhishekvarghese-p4j
    @abhishekvarghese-p4j 18 днів тому

    in css its
    div.stack{
    flex:0 1 100%
    }

  • @rajetmills4985
    @rajetmills4985 Рік тому

    makes no sense