Centering a div with absolute positioning

I know this was probably set a million times, but how can I center a div that has absolute positioning.

I tried this and it does not center it.

You can browse the site here password: springy88

#logo{ position:absolute; width:243px; left: 50%; margin-left: 121.5px; } 
+4
source share
3 answers

You need to use negative margins - margin-left:-121px . This will fix the logo. After that, you will need to position the navigator correctly ...

+5
source

Centering a div is very simple, you know the width and height of the div. Assuming your div has a width of 100 and 100 heights

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

if you are unsure of the size, then you can probably use the jquery method.

+8
source

You can set the value to% 50%, that is: left: 25% or right: 25%; Providing a wrapper is twice the width of an element.

Check here ..

-1
source

Source: https://habr.com/ru/post/1400924/


All Articles