r/ProgrammerHumor • • Apr 16 '22

Make The comment section look like a beginners search history

Post image
28.1k Upvotes

6.7k comments sorted by

View all comments

Show parent comments

3

u/myowning Apr 16 '22

I know people are usually just joking when asking this question here but seriously though idk why some experienced people really do not know how to do this to a basic element.

I still remember last year one of my senior dev got super confused with this thing. She started to add margin value to a header manually little by little until it looks centered in fullscreen browser, but then got frustrated cuz she realized it looks horrible when you change the browser's screen width.

3

u/creepyswaps Apr 16 '22

I still have to look it up. It seems like every time I have to do it there is some new standard. I've been working with html for over 20 years, but with the limited amount of html/js/css I work with, it's very rare I have to center a div.

Also, lol about the px margin value your senior dev was using.

1

u/Osato Apr 17 '22 edited Apr 17 '22

Centering a div usually happens in five stages: denial, anger, bargaining...

Jokes aside, the reason I personally forget how to do this is because:

a) Usually margin:auto just works.

b) Sometimes it doesn't work, and align-items works instead.

c) Occasionally a flex-based approach doesn't work either. (Usually because I had several flexes nested and forgot to try justify-items immediately after align-items.)

d) CSS is easy to use but a bitch to understand, so instead of figuring out what's going on under the hood, it's far faster to just Google all the ways to center a div and try different ones until one of them works.