Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

centering 1

Status
Not open for further replies.

TFfan

Programmer
Jan 18, 2002
192
CA
Is it possible to center your website on a page across resolutions without using tables? With CSS tables seem virtually obsolete except in this one instance.

Right now I get my pages left aligned which is okay, but I'd prefer them to be centered. Right now I'm using top:xxx; left:xxx; position:absolute.

I'm probably asking for a perfect world here, but I thought I'd double check.
 
yes you can! try one of these lovely methods:

position:absolute;
left:50%;
margin-left:-250; /* half the size of the centered content */

or try this:

margin-right:auto;
margin-left:auto;

the second one it usualy best. but sometimes you want something to be offcenter. for exanple, you want you content centered int he page, but your menu right beside it. you can use the first method to position anything relative to the center of the page.
 
Maybe I'm just stupid, but this doesn't seem to be working for me. I've tried:

#back{margin-left:-250;left:50%;position:absolute;width:770px;height:100%;background-image: url(bg.gif);background-repeat: repeat-y;}

and

#back{margin-right:auto;margin-left:auto;width:770px;height:100%;background-image: url(bg.gif);background-repeat: repeat-y;}

The first one sends my page off screen to the left and the second give me a left margin of about 5 or 10 no matter the resolution.

This is just a test page and is the only active id. Any ideas?
 
Figured it out. For anyone else reading this topic with the same problem, use this:

body {
margin:0px 0px; padding:0px;
text-align:center;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top