Example of vertically …
Absolute positioning bases the element’s position relative to the nearest parent element that has position: relative. A passionate front-end developer who cares about CSS, JavaScript and keeping code clean and nifty.
like a block with long paragraph text. If padding and line-height are not options, another solution is to use positioning and the transform property: I am vertically and horizontally centered.
Because the child div's height and width are set less than the height and width of the parent div this positioning is impossible. But you should only pick the one which has better browser support and easy to implement.First we are gonna begin with those methods that have better web browser support & at the end we will look at methods that have less browser support.Let’s say we have an image and we want to center it, First we need to create a div element and an image inside it in HTML and then give it some styles.Now we have an image inside a div, We gave some dimension to both our image and div element and we also added a background of #fff on div element.Now we need to add property of position relative to our parent element and position absolute to our child element which in our case is image element.Now, We are going to give top of 50% to our child element.It’s no vertically center yet, Now all you have to do to vertically center it is to give it a negative margin from top, of half the height of the element you are centering which in our case is image element.Remember: If you also want to center it horizontally then you can use the same trick that we used to center it vertically.Yes, you heard me right! May 4, 2010. How to Center an Absolutely Positioned Element Using CSS . A really simple approach and one of the first (back in the day, everything was tables), is using the behavior of table cells and vertical-align to center an element on the container.