Computers & Electronics

HTML/CSS help

  • Last Updated:
  • Aug 29th, 2010 11:40 am
Tags:
None
Newbie
Jul 18, 2010
63 posts
2 upvotes

HTML/CSS help

How do you make a webpage adjust its position to the center of the page?
I want the content to always be centered, no matter the size of the window, without having to rewrite the code.
5 replies
Sr. Member
User avatar
Aug 18, 2007
964 posts
5 upvotes
<body>
<div id="holder">
content to be centered.
</div>
</body>

CSS:
#holder {margin: 0 auto; width: 900px}
change 900px to whatever you want.
Newbie
Jul 18, 2010
63 posts
2 upvotes
It doesn't work :S
Could it be because all my other <div id> tags are set to position absolute?
Sr. Member
User avatar
Aug 18, 2007
964 posts
5 upvotes
Perhaps. I can't debug your code without seeing it. However, I can assure you that the code I posted will work, on its own.

If you want to link me to whatever you're trying to implement, I can tell you exactly what lines you'll need to change to make it work.
Newbie
Aug 15, 2009
35 posts
Kitchener, ON
if your inner divs are abs positioned, place a position:relative on your holder so they will position relatively to the holder div.

Top