
Design comparison
Solution retrospective
I would like to know about center-middle item alignment. I have always used flex for this project for those alignments. Are there any other ways to achieve it?
Please log in to post a comment
Log in with GitHubCommunity feedback
- @vanzasetia
Hi there! 👋
I can't view your code. I assume that it's because the repository is a private repository. So, make it public instead.
Regarding your question, you can try using grid instead. But, I don't recommend using absolute positioning. It makes the element out of the normal flow which can introduce some bugs.
By inspecting the
body
element I have a few suggestions for you.- First, remove
width
andheight
from thebody
.- Not only setting
width: 100vw
can cause an overflow issue but also by default thebody
element has100%
of width. - For the
height
since it is necessary to make the card vertically center, I suggest usingmin-height
instead. This way, thebody
element is allowed to grow if needed.
- Not only setting
I also notice some inline styling. I suggest moving all the styling to external CSS. It's best to separate the HTML and CSS on their own file. Also, inline styling is not reuseable and hard to maintain.
Hope this helps.
- First, remove
- @ExiviuZ
Set 100vh and 100vw to parent then put margin auto to the child you want to vertically and horizontally center. You can also set display grid then set place-content:center.
https://www.freecodecamp.org/news/how-to-center-anything-with-css-align-a-div-text-and-more/
Join 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