Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > HTML, XHTML and CSS

Reply
 
LinkBack Thread Tools
Old September 8th, 2006, 10:24 PM   #1
New Member
 

Join Date: Sep 2006
Location: denver
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 johnmr is on a distinguished road
Centering a DIV

I am building an interface where I have a DIV that gets made visible when you roll over a certain area. The div contains some nav elements, which are jscript rollovers themselves. I've got the code working to hide and show the DIV and to do the rollovers (I've only done the one in the upper left). Here is what it looks like so far:

http://www.artntech.com/sample/index.html

The problem is, I really want the design to be centered, and since I am using absolute positioning for the DIV, this creates a problem. Here is what it looks like when I center the underlying table:

http://www.artntech.com/sample/index2.html

I'm pretty new to all his, and am stumped as to how to get that DIV element to center and align with the underlying table (since it is centered, I can't really predict exactly where it will be in the window).

I've seen articles saying this kind of thing can be one with CSS and have tried several of the samples I've seen with no luck. Anyone know of a good way to do this? Any help greatly appreciated.

Thanks

Johnmr

*
johnmr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 9th, 2006, 04:02 AM   #2
New Member
 

Join Date: May 2006
Location: in a house
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 HogDog is on a distinguished road
Re: Centering a DIV

1st add this to your body elemant in your style sheet:
body {text-align: center;}

2nd surround everything inside the body tag with <div class="global"> tag
then add the following to your CSS. that should do the trick.

div.global {
position: relative;
margin-left: auto;
margin-right: auto;
width: "what ever the width of the content is" px;
}
HogDog is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 9th, 2006, 08:03 AM   #3
Most Reputable Member
 
spinal007's Avatar
 

Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0 spinal007 has a spectacular aura about spinal007 has a spectacular aura about
Re: Centering a DIV

just add this to your div's css:
margin:0 auto;
__________________
Diego - Web-Developer & London SEO Expert
jQuery Plugins: Multiple File Upload, Star Rating, FCKEditor | NEW: XML to JSON
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 9th, 2006, 10:23 AM   #4
New Member
 

Join Date: Sep 2006
Location: denver
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 johnmr is on a distinguished road
Re: Centering a DIV

thanks very much - I'll try this out and let you know what happens
johnmr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 9th, 2006, 02:05 PM   #5
Elite Veteran
 

Join Date: Aug 2005
Location: That Place
Posts: 2,081
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Rep Altering Power: 0 moojoo will become famous soon enough moojoo will become famous soon enough
Re: Centering a DIV

I don't see the need for absolute positioning on this but eh. What do I know. Since all 4 areas are contained within a containing div wouldn't relative positioning work? I may be wrong.
__________________

moojoo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 11th, 2006, 07:18 AM   #6
Most Reputable Member
 
spinal007's Avatar
 

Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0 spinal007 has a spectacular aura about spinal007 has a spectacular aura about
Re: Centering a DIV

it's soooooooooo simple:
margin:0 auto;

Code:
<style>
#Container{
 width: 780px;
 margin:0 auto;
}
#Row1{ font-size:200%; padding:50px 0px; color:white; background:green; }
#Row2{ font-size:200%; padding:50px 0px; color:white; background:red; }
#Row3{ font-size:200%; padding:50px 0px; color:white; background:blue; }
</style>

<div id="Container">
 <div id="Row1">
  This is row 1
 </div>
 <div id="Row2">
  This is row 2
 </div>
 <div id="Row3">
  This is row 3
 </div>
</div>
__________________
Diego - Web-Developer & London SEO Expert
jQuery Plugins: Multiple File Upload, Star Rating, FCKEditor | NEW: XML to JSON

Last edited by spinal007; September 11th, 2006 at 07:21 AM..
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 11th, 2006, 08:54 AM   #7
Elite Veteran
 

Join Date: Aug 2005
Location: That Place
Posts: 2,081
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Rep Altering Power: 0 moojoo will become famous soon enough moojoo will become famous soon enough
Re: Centering a DIV

Even text-align: center; on the body would work. But I think there are issues preventing that, I need to look and see how he actually centered it.
__________________

moojoo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 11th, 2006, 09:09 AM   #8
Most Reputable Member
 
spinal007's Avatar
 

Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0 spinal007 has a spectacular aura about spinal007 has a spectacular aura about
Re: Centering a DIV

the problem with text-align:center is that you have to set text-align:left/right for all underlying elements...
also, text-align:center is for positioning/aligning text, not elements.

PS.: Moojoo: what's a noob?
__________________
Diego - Web-Developer & London SEO Expert
jQuery Plugins: Multiple File Upload, Star Rating, FCKEditor | NEW: XML to JSON
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 11th, 2006, 10:23 AM   #9
Elite Veteran
 

Join Date: Aug 2005
Location: That Place
Posts: 2,081
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Rep Altering Power: 0 moojoo will become famous soon enough moojoo will become famous soon enough
Re: Centering a DIV

Actually you only have to set text-align:left on the container div. Everything in there will follow suit. You need to do that for IE 5.x anyway since IE 5 doesn't know margin: auto;
__________________

moojoo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 12th, 2006, 05:18 AM   #10
Most Reputable Member
 
spinal007's Avatar
 

Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0 spinal007 has a spectacular aura about spinal007 has a spectacular aura about
Re: Centering a DIV

Good point...
I'll just hope IE 5 is abolished soon enough... lol
__________________
Diego - Web-Developer & London SEO Expert
jQuery Plugins: Multiple File Upload, Star Rating, FCKEditor | NEW: XML to JSON
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 12th, 2006, 09:02 AM   #11
Elite Veteran
 

Join Date: Aug 2005
Location: That Place
Posts: 2,081
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Rep Altering Power: 0 moojoo will become famous soon enough moojoo will become famous soon enough
Re: Centering a DIV

Wishful thinking heh. It will be a long time before everyone gets on Vista, and XP. although I hear IE 7 will be a pushed update to XP so.. lets hope. Too many people still on Win 98/Me/2k.. XP has been around for 6 years now? And I would guess that only 60 - 70% have upgraded to XP. And that may be a generous set of numbers.
__________________

moojoo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 12th, 2006, 10:55 PM   #12
Elite Veteran
 
Ryan Fait's Avatar
 

Join Date: May 2006
Location: Las Vegas
Posts: 3,784
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Ryan Fait is a jewel in the rough Ryan Fait is a jewel in the rough Ryan Fait is a jewel in the rough Ryan Fait is a jewel in the rough
Re: Centering a DIV

Here's to hoping Vista is as good as Tiger. Not that I'll ever switch back to Windows...
Ryan Fait is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 13th, 2006, 09:07 AM   #13
Elite Veteran
 

Join Date: Aug 2005
Location: That Place
Posts: 2,081
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Rep Altering Power: 0 moojoo will become famous soon enough moojoo will become famous soon enough
Re: Centering a DIV

Vista will be close, half of its appearance and functions are a straight up rip of OS X. Right down to the rounded input fields. And their window management is a direct rip of Looking Glass by SUN. Muhahaha. No worries though, Vista may be as good as Tiger or close but leopard will be released first and no way will Vista even compare to Leopard. I however will happily purchase Vista and run it on my Macbook Pro.
__________________

moojoo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
centering , div


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertical centering - please help! mpnuttall HTML, XHTML and CSS 6 April 16th, 2008 07:38 AM
Centering a Page In CSS britishchampion HTML, XHTML and CSS 5 January 3rd, 2008 12:20 PM
Centering website afowler HTML, XHTML and CSS 8 October 24th, 2007 02:59 PM
centering help please RZX Developer HTML, XHTML and CSS 7 August 2nd, 2007 07:58 AM
centering vertically benbacardi HTML, XHTML and CSS 17 May 27th, 2004 09:51 AM


Search Engine Optimization by vBSEO 3.2.0 RC8