@iamsomraj
Posted
Hi,
To center a container both horizontally and vertically using flexbox in CSS, you can apply the following styles to the container:
.container {
display: flex;
justify-content: center; /* Centers horizontally */
align-items: center; /* Centers vertically */
height: 100vh; /* Set the container height to the full viewport height for vertical centering */
}
By using display: flex
, the child elements inside the container will be automatically centered both horizontally and vertically.
This approach centers the container's content regardless of screen size, making it responsive to various devices.
I can see that you have used bootstrap. Personally, I would highly recommend using Tailwind. Let me know if you need any help.
@BossArifSanjaya
Posted
@iamsomraj thanks for the advice, this is very useful for me
@iamsomraj
Posted
Thank you, @BossArifSanjaya, for your prompt response. If you found my reply helpful, I kindly ask for an upvote. This will assist others with similar doubts in discovering the solution more easily.