@MelvinAguilar
Posted
Hi @K-Muzslay ๐, good job for completing this challenge and welcome to the Frontend Mentor Community! ๐
Answering your question here are some suggestions to improve your code:
There are two modern CSS techniques to center elements
Using flexbox layout:
body {
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
Using grid layout
body {
width: 100%;
min-height: 100vh;
display: grid;
place-content: center;
}
More information:
- The Complete Guide to Centering in CSS
- A Complete Guide to Flexbox (CSS-Tricks)
- How TO - Center Elements Vertically (W3Schools) |
- CSS Layout - Horizontal & Vertical Align (W3Schools)
And remove:
main {
/* margin: 0; */
/* position: absolute; */
/* top: 50%; */
/* left: 50%; */
/* -ms-transform: translate(-50%, -50%); */
/* transform: translate(-50%, -50%); */
}
Another tips:
- Use
max-width: 360px
to.container
selector instead of width. - Use
margin: 0.625rem
ormargin: 10px
in thecontainer
selector so that it has some space when viewed on mobile devices.
I hope those tips will help you.
Good Job and happy coding !
Marked as helpful
@K-Muzslay
Posted
@MelvinAguilar Thank you so much! I was sure it can be solved with flexbox, I tried but I was not familiar with the "vh" relative unit. Now I'll keep it in mind.
I haven't learnt grid yet, I will revisit this when I'm at it.
Thank you for the extra tips too!