I’m struggling with CSS Flexbox. Each time I think I’m about to get it in an aha momet, I’m actually two steps backwards. I’m taking The Odin Project course and I’m at the phase where I am building the landing page. I’ve worked on it for 16 straight hours and I’m almost finished. It just looks like shit on a small screen but in fairness, the curriculum did mention that. Otherwise, what I have looks like the goal. I did one or two extra easy touches.

Okay so one question: when is it better to use flex-direction: column and when is it better to use flex-direction row? I’m seriously confused.

  • AverageCakeSlice
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    1 year ago

    So, for flex-direction: column, usually you’ll want to use it when you need multiple items to be consistently spaced vertically. For example, you have a testimonials section on your webpage with some divs that contain quotes, and you want them to be centered in the page, stack on top of each other, and have equal spacing between each quote. This is where flex-direction: column comes in. You just set the flex five to the height you want, slap display: flex and the flex direction properties on it, set justify-content to between, and maybe align-items to center so that all the child divs are in the center of the parent, and voila!

    In real life, you’ll mainly see this used on mobile, where lots of elements need to be stacked on top of each other, but there are cases on other viewports where it makes sense. For example, in lining up fields in a vertical form like a login or sign up page where the username, password, and login/create account buttons are all stacked on top of each other.