This is a discussion on "Centering a DIV" within the Web Page Design section. This forum, and the thread "Centering a DIV are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
Centering a DIV
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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 * |
|
#2
|
|||
|
|||
|
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; } |
|
#3
|
||||
|
||||
|
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
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#4
|
|||
|
|||
|
Re: Centering a DIV
thanks very much - I'll try this out and let you know what happens
|
|
#5
|
|||
|
|||
|
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.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
|
|
#6
|
||||
|
||||
|
Re: Centering a DIV
it's soooooooooo simple:
margin:0 auto;
__________________
Diego - Web-Developer & London SEO Expert jQuery Plugins: Multiple File Upload, Star Rating, FCKEditor | NEW: XML to JSON
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Last edited by spinal007; Sep 11th, 2006 at 12:21. |
|
#7
|
|||
|
|||
|
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.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
|
|
#8
|
||||
|
||||
|
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
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#9
|
|||
|
|||
|
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;
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
|
|
#10
|
||||
|
||||
|
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
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#11
|
|||
|
|||
|
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.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
|
|
#12
|
||||
|
||||
|
Re: Centering a DIV
Here's to hoping Vista is as good as Tiger. Not that I'll ever switch back to Windows...
|
|
#13
|
|||
|
|||
|
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.
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
|
![]() |
| Tags |
| centering, div |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vertical centering - please help! | mpnuttall | Web Page Design | 6 | Apr 16th, 2008 12:38 |
| Centering a Page In CSS | britishchampion | Web Page Design | 5 | Jan 3rd, 2008 17:20 |
| Centering website | afowler | Web Page Design | 8 | Oct 24th, 2007 19:59 |
| centering help please | RZX Developer | Web Page Design | 7 | Aug 2nd, 2007 12:58 |
| centering vertically | benbacardi | Web Page Design | 17 | May 27th, 2004 14:51 |