this post was submitted on 21 Aug 2023
12 points (92.9% liked)

Web Development

3434 readers
1 users here now

Welcome to the web development community! This is a place to post, discuss, get help about, etc. anything related to web development

What is web development?

Web development is the process of creating websites or web applications

Rules/Guidelines

Related Communities

Wormhole

Some webdev blogsNot sure what to post in here? Want some web development related things to read?

Heres a couple blogs that have web development related content

CreditsIcon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

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.

top 10 comments
sorted by: hot top controversial new old
[–] FlickOfTheBean@lemmy.world 18 points 1 year ago* (last edited 1 year ago) (2 children)

Best to not switch away from the default (row) unless you really know what you're doing. Here's the guide I always consulted for flexbox direction help. I just consulted it until I got the feel for it. I could guess at what you're doing but I think this resource will be better than me hemming and hawing over what you're trying to do: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

So some tips:

  1. column flips what the actual keywords of flex do (justify-content starts to act like align-items and visa versa).
  2. it's easier to develop for small screens and then expand up to large screens. This is because you already know what you'll have to expand from and you won't have to squish anything down. (I'm not saying you should restart your project though, this is a future tip only. Only restart if everything is truly fubar.)

+1 for this resource, I printed out a cheatsheet because I was looking it up every time

Thank you!!!! This is great!

[–] shootwhatsmyname@lemm.ee 8 points 1 year ago (1 children)

Here is an awesome interactive article by Josh W Comeau on flexbox. It has some good examples in there on what you’re talking about too.

In many situations, the default flex-direction: row (elements laid out left to right) is what you want when using flex.

flex-direction: column on the other hand lays elements out from top to bottom. This is basically how elements are laid out anyways—that’s why it’s less common to use this direction. You would typically use this direction on a container that has a larger height than its child elements because now the flex properties can actually position elements within the container and utilize the empty space. Otherwise, most flex properties don’t do anything in this direction.

I think I looked at this one. I'll probably have to read it again. Thank you for your help. 😄

[–] AverageCakeSlice@sh.itjust.works 3 points 1 year ago* (last edited 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.

[–] ulkesh@beehaw.org 3 points 1 year ago

When you want your child elements laid out left to right: flex-direction: row

When you want your child elements laid out top to bottom: flex-direction: column

[–] w3dd1e@lemm.ee 1 points 1 year ago (2 children)

Yo! I’m in exactly the same place in my Odin Project curriculum. I’m also actually doing OpenClassrooms bootcamp (through my employer). I didn’t struggle too much with flex (except in column format. It’s so bad.) feel free to DM me and chat about it if you want a project partner! I’m on discord too. Same username.

[–] w3dd1e@lemm.ee 1 points 1 year ago

I was talking to my teacher about how annoying flex box columns are and he was saying it wasn’t designed with columns in mind and he expects it to be updated in some future version of CSS. But until then, it depends how you want the box to grow/shrink.

I also found, you can trick it into a column while still using a row if you give the items a 100% width of their container and let them wrap to the next row. It might not always be right to do that, but it could probably work in some situations if it’s not going well in column format.

Good luck!

Hey! Sorry I am just seeing this now I pushed past the difficulty and kept trying different things until I got it. The result of my landing page is housepanther landing page. It turned into a lot of fun.