View Full Version : Resolved Absolute Center?

11-24-2012, 04:07 AM

I'm trying to achieve an absolute center on my website, however upon changing the screen size, the image does not stay in the center.


Any ideas?

Best Regards,

11-24-2012, 04:27 AM
You need to use these in the CSS for your image:

margin-left: -[Image Width / 2]px; //find this yourself.
left: 50%;

11-24-2012, 04:28 AM
This should help: http://www.codingforums.com/showpost.php?p=182254&postcount=9

11-24-2012, 05:09 AM
This should help: http://www.codingforums.com/showpost.php?p=182254&postcount=9

when the screen gets too small, the content will disappear off the left side without so much as a scrollbar, making that area of the page completely unaccessable

I've never had that problem before. Have an example?

11-24-2012, 06:55 AM
Hello MrTIMarshall,
That post Custard7A links to leaves out two very important requirements, see below:

To center an element you need three things:

a valid DocType
an element with a width
that elements right/left margins set to auto

11-24-2012, 10:32 AM
I don't know! I was just thinking how this is the most commonly asked question as far as I've seen, so I thought there should be something stickied about it. That post I linked was sticky in this very section. I've only ever used the margin: auto method.

11-24-2012, 05:12 PM
The problem is, I plan to have grass on either side as well, however this is the center of the website where I need to get this working before I implement anything else.


This is what I'm rebuilding so you can see how I was doing things, which will be the same, however I understand how media queries work now so I thought I would start from scratch to look at the other one for reference.

Thank you for the current posts :)