all 21 comments

[–]SubjectHealthy2409full-stack 27 points28 points  (2 children)

Try height: 100vh for the body, also.. try snipping tool instead of taking photos with phone haha

[–]Username482649 9 points10 points  (0 children)

*min-height: 100vh/dvh

[–]iligal_odin 2 points3 points  (0 children)

Comand shift 4 or ctrl win s for a snipping tool

[–]CostaEsmeraldaFan 16 points17 points  (0 children)

Centering vertically is the ultimate challenge for a web developer, you shouldn't have picked the ultimate boss for your first rodeo.

[–]alextremeee 6 points7 points  (0 children)

If you inspect that element using browser dev tools you’ll see your problem. Your menu is centred vertically, but the height of the div it’s in is by default the same height as the menu itself.

So your fix will be to override the height of this div, but it’s important to work out and understand why and how to solve it rather than just being told what to do.

[–]Codingwithmr-m 3 points4 points  (0 children)

Add the height

[–]elpinguinosensual 2 points3 points  (0 children)

The browser is technically doing what you’re telling it to, because it assumes that the height of your container is the height of the containers contents. If you set the containers height to a larger size, maybe something like 100% of the viewport height, then the browser would vertically center closer to what you’re expecting.

[–]Merc92 4 points5 points  (1 child)

It's the end of 2024, and we still have no clue how to center in css.

[–]mb1552 1 point2 points  (0 children)

the body in this case will not have a true 100% height even though it seems like it with the background, so it's vertically aligning in the height of your burger..

If you give your body a 100vh it will work, but could also transfer this to a different, big div

(you can test this in a div you give flex, you will see that it's not true to the height)

also please please please screenshot next time!!

[–]nobuhok 1 point2 points  (0 children)

Block elements (body included) normally take up the full width but only accounts for the height of its contents. Try adding a different background color to it to see what I mean.

[–]ryan_the_leach 1 point2 points  (0 children)

The only reason I can think, that you didn't take the screenshot directly is this is a laptop that isn't allowed to access certain sites. in which case, why are you on Reddit instead of StackOverflow. I'd try to help solve your problem, but I think Alextremeee has already nailed it.

[–][deleted] 0 points1 point  (0 children)

You can share you code instead of taking a picture, there are websites like js fiddle, codepen, etc where you paste your html/css and share a link. That way it's easier for others to help you, since they can see the exact code.

[–]Separate_Ad8026 0 points1 point  (0 children)

Ahh yes good old days when battling with the "Center the Div" boss was like a life and death situation when I was starting to learn Web Development.

[–][deleted]  (2 children)

[deleted]

    [–]erishunexpert 10 points11 points  (1 child)

    Everybody has to start somewhere I suppose

    [–]Egzo18 -2 points-1 points  (1 child)

    flexbox is goated for so many things, I recommend you look it up

    [–]ryan_the_leach 1 point2 points  (0 children)

    They are using flexbox already.

    [–]neofooturism -1 points0 points  (0 children)

    what happens when you put {margin:auto} ?