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

Thread: Trying to center my tables/divs?

  1. #1
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default Trying to center my tables/divs?

    Okay my website is here and I am trying to center the whole thing. Like The image, in the center, which I seem to have done just by making the width of the div table 100% and then just using
    Code:
    <center> </center>
    around the imagemap in the div. However, when I tried to do that with the #sidebardiv and #contentdiv I changed the "left" value to percentages. But it seems it works on my screen however when I use browser shots its not like that on all screens. Here is what it looks like on mine. And here is the browser shots page.

    Overall: I would like my whole page (except the text) to be in the center of every screen. Can someone please help?
    Last edited by ModernRevolutions; 12-20-2010 at 11:08 PM.
    ------------------
    Check out my site here and let me know what you think

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    <center> is depreciated, use text-align: center in replace. Of course, <center> and text-align only align text, not a block element. To center something horizontally, use margin:0 auto;

    Code:
    <div style="margin:0 auto; width: 50px; height: 50px; background: green">
      I should be in the top center of your page!
    </div>
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    That centers them but I want both my side bar and content bar/boxes in the middle (but not overlapping). I want them about 75-100px away from each other. And as for my image, when I put text-align: center, it centers it but also shifts it down a few pixels for some reason :/
    ------------------
    Check out my site here and let me know what you think

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You want it to look like this: http://modernrevolutions.vivid-avenue.net/1680x1050.jpg, right? Just double checking.
    Jeremy | jfein.net

  5. #5
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    Yup, want it to look like that and have the top image, and the 2 tables to center no matter the screen resolution so the website is more compatible
    ------------------
    Check out my site here and let me know what you think

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What I suggest:
    • Get rid of the position: absolute; muddy slush
    • Put the sidebar and content div in a container div called something like #content-wrap
    • Give #content-wrap margin: 0 auto;
    • Give the sidebar float:left;
    Jeremy | jfein.net

  7. #7
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    I did that and now they aren't centered, they are smushed up to the top left. God i hate divs D: If i knew another way that was just as easy I would use that
    ------------------
    Check out my site here and let me know what you think

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Alright, I suggest starting with a neat little template like this:
    HTML Code:
    <html>
    	<head>
    		<title>Layout</title>
    		<style type="text/css">
    		body 		{ color: #000; font-family: arial; font-size: 12px; margin: 0; padding: 0; }
    		div 		{ margin: 0; padding: 0; }
    		#page-wrap	{ width: 100%; }
    		#header 	{ background-color: #ccc; height: 100px; width: 100%; }
    		#body-wrap 	{ width: 95%; margin: 25px auto; }
    		#sidebar 	{ background-color: #ccc; float: left; height: 200px; width: 19%; }
    		#content 	{ background-color: #ccc; float: left; height: 300px; width: 79%; margin-left: 2%; }
    		</style>
    	</head>
    	<body>
    		<div id="page-wrap">
    			<div id="header">Header</div>
    			<div id="body-wrap">
    				<div id="sidebar">
    				&nbsp;
    				</div>
    				<div id="content">
    				&nbsp;
    				</div>
    			</div>
    		</div>
    	</body>
    </html>
    And build on that, maintaining the neatness of the code.
    Jeremy | jfein.net

  9. #9
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    Okay that is basically working. WOOT! But now my header wont center >.< http://modernrevolutions.vivid-avenue.net/index3.php Here is the live version that I have edited and all that jazz
    ------------------
    Check out my site here and let me know what you think

  10. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I thought you wanted: http://modernrevolutions.vivid-avenue.net/1680x1050.jpg
    The header is 100%.
    Jeremy | jfein.net

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
  •