@coderSuresh
Posted
To center a div, you can use flexbox. For example, you have a div with a class name container that contains everything inside a body tag. In order to center that div, you can use flexbox as:
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
In this code, we are giving a height of 100 vh (viewport height) which covers the full height of the screen. "align-items: center" centers the div vertically, and "justify-content: center" centers the div horizontally.
I saw that we have a section with a class name container. To center that container, instead of giving it a margin of 10vh, you can use flexbox as shown above.
Let me know if this helped you. If it didn't I am always here for you. Thanks for reading.
Marked as helpful