Design comparison
Solution retrospective
i found dificult to center the div , because it is easy to center it from sides of browser window , but i could not center it vertically . Did display: flex ; on body and then justify-content: center ; align-items: center; it didn't work , everything i tried didn't work so i had to use margin with exact pixels :( sadly.
Community feedback
- @djbedfordPosted about 2 years ago
Hey, you said you had trouble centering the div vertically, you're on the right track using flexbox with justify content and align items but you must also remember to set the height. The reason for this is because a div just takes up as much space as the content inside of it does, so when trying to center it vertically it has no room to move, in order to align it vertically you can set the height to 100vh which will give it the room to center it. Ideally you would wrap the div within a main tag and add the flex box and height styles there, this should solve your issue with vertically centering. You can also remove the top and bottom margin as they will no longer be required.
Apart from that good job!
Marked as helpful3 - @SleepySleepyFoxPosted about 2 years ago
You might try to center a div with: position: absolute; transform: translate(50%, -50%); right: 50%; top: 50%;
Marked as helpful0@axraxaPosted about 2 years ago@SleepySleepyFox that's a nice way to solve it , but i started html and css 2weeks ago and didn't go that deep yet , have not checked transform element . thx for your time and information <3
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord