Skip to main content

Command Palette

Search for a command to run...

How To Center <div> Vertically?

When I am not able to center a div container...

Updated
โ€ข1 min read
How To Center <div> Vertically?
P

๐Ÿ‘‹ Hey! I'm Prakash Naikwadi. I have a Bachelor's degree in Computer Engineering๐Ÿคฉ

I am currently learning๐Ÿ“˜ ๐Œ๐„๐‘๐ ๐’๐ญ๐š๐œ๐ค ๐ƒ๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ฆ๐ž๐ง๐ญ.

๐Ÿ… ๐†๐ข๐ญ๐‡๐ฎ๐› ๐๐ซ๐จ๐Ÿ๐ข๐ฅ๐ž: https://github.com/prakash-naikwadi

๐‡๐ž๐ซ๐ž ๐š๐ซ๐ž ๐’๐จ๐ฆ๐ž ๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌ๐ž๐ญ๐ฌ ๐ญ๐ก๐š๐ญ ๐ˆ ๐๐จ๐ฌ๐ฌ๐ž๐ฌ๐ฌ๐ž๐...

๐…๐ซ๐จ๐ง๐ญ ๐„๐ง๐: โ€ข HTML5 (Intermediate Level)
โ€ข CSS (Intermediate Level)
โ€ข JavaScript
โ€ข React

๐๐ซ๐จ๐ ๐ซ๐š๐ฆ๐ฆ๐ข๐ง๐  ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž๐ฌ: โ€ข Java โ€ข C โ€ข C++

Thank you for reading. Have a wonderful day๐Ÿค—

Hello๐Ÿ‘‹,
I am learning CSS past 15days now and I am working on some projects where I have to center a whole card component vertically and horizontally in the middle of a page.

I have learned from my previous project How To Center an Element horizontally, I have put the code below(This is in every tutorial you follow):

By Setting left and right margin as auto:

index-html.png

horizontal-align-using-margin-style-css.png

But, When I tried to align vertically by setting the Top & Bottom margin as auto but it did not work ๐Ÿ˜ค

Why margin auto does not work: https://www.hongkiat.com/blog/css-margin-auto/ this is a great article to read.

So after hustling through google searches I got to know that this is a common problem every programmer had faced in their CSS journey.

So I came to know that there are a lot of techniques out there for this problem and came across this article:
6 CSS Tricks to Align Content Vertically: https://www.hongkiat.com/blog/css-tricks-vertical-align-content/

I think in this article there is all possible daily occurring vertically aligned content patterns are given.

๐“๐ก๐š๐ง๐ค ๐˜๐จ๐ฎ ๐…๐จ๐ซ ๐‘๐ž๐š๐๐ข๐ง๐  ๐‡๐š๐ฏ๐ž ๐€ ๐†๐จ๐จ๐ ๐ƒ๐š๐ฒ ๐Ÿ˜€

More from this blog

Untitled Publication

9 posts