newbie trying to center a menu on the page

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
jhherring
Advanced
Advanced
Posts: 11
Joined: Fri Jul 30, 2004 7:35 pm

newbie trying to center a menu on the page

Post by jhherring »

I don't yet have the example code posted anywhere, and hope that I don't need to, just to answer something that's no doubt very very simple. I also know that this has been tackled before, many times, and I did read the FAQs, so at least I'm trying!

Anyway, placing the menu inside a table cell with align="center" doesn't do any good. Silly of me.

I even tried pasting the suggested

Code: Select all

screenposition="center;middle";
into what I hope was the right place on the page. Nothing.

Obviously, I'm doing something wrong. Can anyone take pity on a newbie (signed up with Milonic just today) and tell me where, exactly, I should be placing the code to get the whole menu centered on the page?

I'd be eternally grateful.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

You are placing the menu in a table, the position is relative. Align=center refers to the text not the menu. You can't use screenposition=center because it's in a table and again the position is relative. One option: in whichever table cell you want to place the menu and have it centered, make a nested table with one cell for the menu and align the table center.

Code: Select all

<td>you want the menu here, so you put <table border="0" cellspacing="0" cellpadding="0" align="center"><tr><td>and place the menu inside this. This table would center in the other table's cell so the menu would be centered in that cell since it goes where this table is.</td></tr></table></td>
Hope that made sense.

Ruth
jhherring
Advanced
Advanced
Posts: 11
Joined: Fri Jul 30, 2004 7:35 pm

newbie trying to center a menu on the page

Post by jhherring »

(a) Thank you very much for your reply.

(b) I'm sure you're on to something, but I still can't quite get it. You can now take a look at it yourself, if you'd be so kind:

http://www.johnherring.net/cypressbay/m ... t-001.html

Take a look at the source for the HTML file -- I commented out the table structure I copied from you, since I couldn't get it to work. You could remove the comments and see whether it works for you, or maybe the error in my code is something that will just leap out at you, since you know what this is supposed to look like.

I know that there's a top=0; and left=0; in the style, but playing with that didn't seem to help any.

Again, many thanks for whatever help you can offer.

I'm getting ready to tell the powers that be that we really should buy this product, and I want to get all the wrinkles ironed out first.

Looking forward to your reply.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Uncomment your table, then remove the script calls from the table and put them all immediately after the body tag and before anything else. Then check this linkand the information on how to place a menu in the table. You cannot put just the code in and have it work in all browsers, it will work in some browsers, break in many others, and even become unusable in others. The only thing that goes in the table is the 'main' always visible menu, the one that would have all the submenus come off it. Look at the that table example page and see how they place the main menu inside script tags and also include the drawMenus(); The rest of the submenus remain in the data file and also keep a drawMenus(); and that file gets called with the other 3 files. Once it is placed like that and you also inlcude the extra table which you have centered from the previous post then the menu will center. Just for information, if you don't need to put it in a table, then you could use the screenposition="center" and it would place the menu in the exact center of the screen.

If you need more help, give a yell.

Ruth
jhherring
Advanced
Advanced
Posts: 11
Joined: Fri Jul 30, 2004 7:35 pm

newbie trying to center a menu on the page

Post by jhherring »

That was it!

You're right, of course. Everything you suggest leads me to what looks like the right solution. It's nothing short of amazing how well it seems to work! (I can't see the menus at all using Win/NN4.07 or Win/NN4.77, but that may be something I can live with.)

By the way, you mention needing to keep the drawMenus(); statement in BOTH the menu_data.js file AND the main HTML file, but when I did this I accidentally omitted it from the menu_data.js file and it still worked! Am I overlooking something?

I'll post the code later today, if you want to take a look.

But either way . . . .

Thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you!
jhherring
Advanced
Advanced
Posts: 11
Joined: Fri Jul 30, 2004 7:35 pm

newbie trying to center a menu on the page

Post by jhherring »

OK, here's the most up-to-date code I've got.

http://www.johnherring.net/cypressbay/m ... t-002.html


Everything looks great, thanks to your help, but I still wonder about the stuff I mentioned in my last post -- there NO drawMenus(); statement in the menu_data.js file (only in the HTML file), and things seem to work fine anyway.

Also, I notice while using Win/IE 6 that the first time you mouse over the "Home" menu, it sometimes looks a little "off" -- the right-hand vertical border for the whole drop-down menu looks like it's too far to the right. Just a couple of pixels. Mouse around with the other menus, though, and the problem with this one just magically goes away when you go back to it. This is something I can definitely live with, it's so small a thing.

Anyway, thanks to you, it seems to be doing what I need. Many, many thanks. I'm delighted.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I don't know about leaving the drawMenus out of the js file. It may be that it will work in some browsers and not work in others, so I would suggest you leave it as the directions state since it is tested in browsers following those directions. I notice that the menu is right at the top of the page. If that is where it is going, I really suggest you remove it from the table and put in the code for screenposition. Putting it in tables works as noted but as new browsers come into being and old ones are changed something might happen. If you decide to use this then put the main menu back in the .js file, and in the definition where you list style= put in screenposition="top;center"; That will put the menu in the top and center of the screen no matter what size/resolution the screen might be. If you want it centered but maybe down some pixels you can do that also. You would specify the top position: top="whateverpixels"; and screenposition="center"; As for the netscape browsers, just so you know it works in Netscape4.79.

Ruth
Post Reply