Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Posts
    419
    Thanks
    52
    Thanked 1 Time in 1 Post

    Absolute Center?

    Hello,

    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.

    http://sunlightgardenservices.co.uk/index-new2.html

    Any ideas?

    Best Regards,
    Tim
    Last edited by MrTIMarshall; 11-24-2012 at 09:00 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2012
    Posts
    168
    Thanks
    5
    Thanked 11 Times in 11 Posts
    You need to use these in the CSS for your image:

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

  • #3
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts

  • #4
    Regular Coder
    Join Date
    Mar 2012
    Posts
    168
    Thanks
    5
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by Custard7A View Post
    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?

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello MrTIMarshall,
    That post Custard7A links to leaves out two very important requirements, see below:

    To center an element you need three things:
    1. a valid DocType
    2. an element with a width
    3. that elements right/left margins set to auto
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #6
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Nov 2010
    Posts
    419
    Thanks
    52
    Thanked 1 Time in 1 Post
    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.

    http://sunlightgardenservices.co.uk/index-new.html

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •