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?
Community feedback
- @vanzasetiaPosted over 2 years ago
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.
2 - First, remove
- @ExiviuZPosted over 2 years ago
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/
0@vanzasetiaPosted over 2 years ago@ExiviuZ Never use
100vw
onbody
as it doesn't account for scrollbars when present. It may only ever introduce potential overflow/scroll bugs.Also, avoid setting a specific height on
body
element. It will not allow it to grow if needed. Usually, it cause an issue on mobile landscape view where the card element is getting cut off.1
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