Centre align a position: absolute element in CSS

Photo by Johannes Plenio on Unsplash

Let’s align an element with position as absolute today. I saw a number of ways on stack overflow but only got this one working.

All we need to do is create a parent element to the one which is having position as absolute and set it’s position property as relative in css.

Then add the following css properties to the element that has position as absolute and needs to be centred.

And that is all we needed to do, your element is positioned at the centre now.

You can find the example code here.

Thanks for reading.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store