Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Center content in big div

  1. #1
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Center content in big div

    I am working on a side scrolling project and am having trouble with centering the individual pages content. I made each stage 2000px in width and my body has an assigned width so they can stack side by side instead of one on top of the other.

    Below is a link to see a demo of the site. Can anyone help me figure out how to center the contents according to the browser size? I tried using percentages in my CSS but it's using the body instead of each stage div to place itself.

    Click Here for the demo site

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    You can position a div, without giving it values for width and height, by simultaneously using top / bottom and left / right values. For instance:
    <div style="position: absolute; left:50px; top: 50px; right: 50px; bottom: 50px; background: red">
    <div style="position: absolute; left:200px; top: 200px; right: 200px; bottom: 200px; background: yellow">Some text</div>
    </div>

    ===
    Arie Molendijk.
    Last edited by molendijk; 09-22-2011 at 07:35 PM. Reason: Correction

  3. #3
    Join Date
    Dec 2004
    Posts
    177
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default

    something like text-align:center in the stage divs' css?
    Verzeihung!

  4. #4
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by molendijk View Post
    You can position a div, without giving it values for width and height, by simultaneously using top / bottom and left / right values. For instance:
    <div style="position: absolute; left:50px; top: 50px; right: 50px; bottom: 50px; background: red">
    <div style="position: absolute; left:200px; top: 200px; right: 200px; bottom: 200px; background: yellow">Some text</div>
    </div>

    ===
    Arie Molendijk.
    Hey Arie, thanks for the tip, I changed things up a bit. I added a container div in the center that holds the contents and made it absolute with a top, left, right and bottom of 25% and it centers in IE, FF and Chrome everytime. Your suggestion of changing it to absolute and creating equal amounts on all sides, turned the light on in my head.

  5. #5
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Spoke to soon, when I apply the container div to all the pages, all their contents get dragged onto the first stage. They are using my browser window and not each stage div to place themselves. I am still stuck on finding a solution. I just want the background color to fill but have the contents in the center align right in the dead center and not scale.
    Last edited by nate51; 09-22-2011 at 09:49 PM.

  6. #6
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Minos View Post
    something like text-align:center in the stage divs' css?
    Does not work.

  7. #7
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Quote Originally Posted by nate51 View Post
    Spoke to soon, when I apply the container div to all the pages, all their contents get dragged onto the first stage. They are using my browser window and not each stage div to place themselves. I am still stuck on finding a solution. I just want the background color to fill but have the contents in the center align right in the dead center and not scale.
    Try using pixels instead of percentages. If that doesn't help, give me a link to the problematic pages + comments.
    ===
    Arie.

  8. #8
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    I would say it sounds like a % problem too. Got a link to your site?

  9. #9
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    @molendijk @itivae link is in first post. I am starting to assume it's not common practice to layout the content in the center of the div as all the horizontal scrolling sites I have seen seem to snap the content to the top left, even if it looks centered it's more dominant to the top left and does not scale when the browser is re sized.

  10. #10
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    The link in the first post is what you tried right from the beginning, so I can't see why my idea doesn't work.
    ===
    Arie.

Bookmarks

Posting Permissions

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