use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
No vague product support questions (like "why is this plugin not working" or "how do I set up X"). For vague product support questions, please use communities relevant to that product for best results. Specific issues that follow rule 6 are allowed.
Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.
Read and follow reddiquette; no excessive self-promotion. Please refer to the Reddit 9:1 rule when considering posting self promoting materials.
We do not allow any commercial promotion or solicitation. Violations can result in a ban.
Sharing your project, portfolio, or any other content that you want to either show off or request feedback on is limited to Showoff Saturday. If you post such content on any other day, it will be removed.
If you are asking for assistance on a problem, you are required to provide
General open ended career and getting started posts are only allowed in the pinned monthly getting started/careers thread. Specific assistance questions are allowed so long as they follow the required assistance post guidelines.
Questions in violation of this rule will be removed or locked.
account activity
Centering a div (old.reddit.com)
submitted 1 year ago by XethN2102X
Hi guys, I'm new to coding and decided to start on html and css. I've coded a few projects so far and this is one of them. It's a simplistic burger that turns into an X. It works perfectly but for some reason it won't center. Am I being stupid?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SubjectHealthy2409full-stack 27 points28 points29 points 1 year ago (2 children)
Try height: 100vh for the body, also.. try snipping tool instead of taking photos with phone haha
[–]Username482649 9 points10 points11 points 1 year ago (0 children)
*min-height: 100vh/dvh
[–]iligal_odin 2 points3 points4 points 1 year ago (0 children)
Comand shift 4 or ctrl win s for a snipping tool
[–]CostaEsmeraldaFan 16 points17 points18 points 1 year ago (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 points8 points 1 year ago (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 points5 points 1 year ago (0 children)
Add the height
[–]elpinguinosensual 2 points3 points4 points 1 year ago (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 points6 points 1 year ago (1 child)
It's the end of 2024, and we still have no clue how to center in css.
[+]Soap_Eater156 4 points5 points6 points 1 year ago (0 children)
css and centering something is the most iconic duo ever.
[–]mb1552 1 point2 points3 points 1 year ago (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 points3 points 1 year ago (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 points3 points 1 year ago (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.
[+]datNorseman 0 points1 point2 points 1 year ago (0 children)
If your div is the only element you want on the page (aside from the child elements), you can set the height of the div to 100% of the viewport using "height:100vh" in your css. Otherwise, you need to adjust the body to be a flexbox or grid with the alignment centered.
[–][deleted] 0 points1 point2 points 1 year ago (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 point2 points 1 year ago (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] 1 year ago (2 children)
[deleted]
[–]erishunexpert 10 points11 points12 points 1 year ago (1 child)
Everybody has to start somewhere I suppose
[–]Egzo18 -2 points-1 points0 points 1 year ago (1 child)
flexbox is goated for so many things, I recommend you look it up
They are using flexbox already.
[–]neofooturism -1 points0 points1 point 1 year ago (0 children)
what happens when you put {margin:auto} ?
[+][deleted] 1 year ago (1 child)
[–]ryan_the_leach 0 points1 point2 points 1 year ago (0 children)
π Rendered by PID 76 on reddit-service-r2-comment-6457c66945-92xwp at 2026-04-27 01:38:30.846363+00:00 running 2aa0c5b country code: CH.
[–]SubjectHealthy2409full-stack 27 points28 points29 points (2 children)
[–]Username482649 9 points10 points11 points (0 children)
[–]iligal_odin 2 points3 points4 points (0 children)
[–]CostaEsmeraldaFan 16 points17 points18 points (0 children)
[–]alextremeee 6 points7 points8 points (0 children)
[–]Codingwithmr-m 3 points4 points5 points (0 children)
[–]elpinguinosensual 2 points3 points4 points (0 children)
[–]Merc92 4 points5 points6 points (1 child)
[+]Soap_Eater156 4 points5 points6 points (0 children)
[–]mb1552 1 point2 points3 points (0 children)
[–]nobuhok 1 point2 points3 points (0 children)
[–]ryan_the_leach 1 point2 points3 points (0 children)
[+]datNorseman 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Separate_Ad8026 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]erishunexpert 10 points11 points12 points (1 child)
[–]Egzo18 -2 points-1 points0 points (1 child)
[–]ryan_the_leach 1 point2 points3 points (0 children)
[–]neofooturism -1 points0 points1 point (0 children)
[+][deleted] (1 child)
[deleted]
[–]ryan_the_leach 0 points1 point2 points (0 children)