HOW TO CENTER ABSOLUTE ELEMENT IN DIV ?

How to center absolute element in div i.e I need to place a div (with position:absolute;) element in the center of my window.?

Create the any class mentioned as below and assign it to your div..inner {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

Here the clue is, that left:50% is relative to the parent while the translate in transform is relative to the elements width/height.

This way you have a perfectly centered element, with a flexible width on both child and parent.This works even if the child is bigger than the parent.

You can also center it vertically with this (Note : width and height of parent and child can be totally flexible(i.e. Unknown)). cheap hotels

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>