Design comparison
SolutionDesign
Solution retrospective
Why my div is not centered vertically?? And, why my image aren't having same padding in all coordinates???
Community feedback
- @denieldenPosted almost 3 years ago
Hi ANKUR,
Your div is not vertically centered because the
margin
property does not center the element but has the task of creating a margin between it and what is around it.I have a few suggestions for you:
- To center the cards on the page try using Flexbox, it can help you better: give the flexbox and
height
properties to the body and remove allmargin
from thediv
. Read here -> Flex guide - Note: Flexbox aligns to the size of the parent container. You can use the
vh
measurement for the height... Viewport Height handles the sizing of an element in relation to the height of the browser window. - try use different measure for the card
width
, not%
Hope this help :)
1 - To center the cards on the page try using Flexbox, it can help you better: give the flexbox and
- @fayax555Posted almost 3 years ago
Give
height: 100vh; display: grid; align-items: center
to your body. To make the image fit the container, give your imagemax-width: 100%
, then give some padding (for all sides) to your div.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