Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-06-2005, 07:41 PM   #1
Member (10 bit)
 
Join Date: Jul 2002
Location: University of California, Santa Barbara
Posts: 800
CSS center positioning problem

What I want to do is position the content section of the page in the middle of the browser window (below the title bar) fixed at 600px wide with a different background color from the rest of the page and a black 1px border around it. I have the whole section I want to position thusly inside a
with a corresponding entry in the linked CSS file.

While typing this post I decided to do some more googling, and in the process I answered my own question with This CSS tricks page

I just need to enclose it in a container given these properites:
Code:
{
   width: 600px;
   margin: 0 auto;
   border: 1px solid black;
}
Which will make the browser insert margins equally around the content, thus centering it. This is actually something I'd been puzzling over for some time since a previous webpage I made, so I hope some people here find it useful.
mattg2k4 is offline   Reply With Quote
Old 03-06-2005, 09:33 PM   #2
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Could also be done quite easily with tables.
__________________

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row
mairving is offline   Reply With Quote
Old 03-07-2005, 04:07 AM   #3
Member (10 bit)
 
Join Date: Jul 2002
Location: University of California, Santa Barbara
Posts: 800
That's true, and it's how I originally did it, but I wanted to do it with CSS so it would be easy to change later on all of the different pages that will be in this project, which is of course one of the great things about CSS.
mattg2k4 is offline   Reply With Quote
Old 03-08-2005, 12:51 PM   #4
Member (4 bit)
 
Join Date: Mar 2005
Posts: 14
Send a message via MSN to J.K. Bowman
Hey Matt..

Ya want to center a DIV? - Try this in your CSS

margin-right: auto;
margin-left: auto;
J.K. Bowman is offline   Reply With Quote
Old 03-09-2005, 11:58 AM   #5
Member (10 bit)
 
Join Date: Jul 2002
Location: University of California, Santa Barbara
Posts: 800
Thanks J.K. but that is functionally the same as margin: 0 auto;, because it makes the top and bottom margins = 0, and the left and right margins = auto.

The shorthand method for setting margins is margin: top right bottom left;, if one is specified, all margins are that one, if two or three are specified, then the missing ones are inferred from the margin opposite them (ie left=right and top=bottom).
mattg2k4 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:18 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2