Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering a div with absolute positioning

I know this has probably been asked a million times, but how do I center a div that has absolute positioning.

I have tried this and it does not center it.

You can view the site here password:springy88

#logo{ position:absolute; width:243px; left: 50%; margin-left: 121.5px; }
like image 749
Cool Guy Yo Avatar asked Dec 17 '22 02:12

Cool Guy Yo


1 Answers

Centering a div is very easy of you know the width and height of the Div. Assuming that your div has 100width and 100 Height

div {
    position:absolute;
    left:50%;
    top;50%;
    margin-left:-50px;
    margin-top:-50px;
}

if you are not sure about the dimentions , then probably you can go for a jquery method.

like image 139
Naveen Bhaskar Avatar answered Dec 27 '22 01:12

Naveen Bhaskar