HTML : Centering a div of unknown height and width
Rajesh Kumar Yadav
Posted on May 17, 2021
Let's create a div with some dummy content as -
<div class="content">This works with any content</div>
Now let's apply some css to allow this content to be in center:
.content {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
I know approx 10-15 ways to center html content, if you're interest then please comment below, I'll write an article on this topic as well.
With all that being said, I highly recommend you keep learning!
Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.
💖 💪 🙅 🚩
Rajesh Kumar Yadav
Posted on May 17, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.