Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Horizontally Centering an Array on Different Screens

Status
Not open for further replies.

xyzuser

Technical User
Aug 13, 2008
96
US
Inexperienced user question:

I have a JavaScript array (downloaded, not my own)) that displays a dropdown menu and specifies style=position: absolute; I've changed the top to where I want the menu to be vertically but it has a complex series of formulae (with meaningless variable names) to set the left position and the width .

The menu displays fine on some screens that have less resolution (800x600) or smaller browser windows but are completely to the left and not centered on other screens.

What would I have to do to make this displayed menu be horizontally centered in every browser window? (I realize the answer may require more experience than I have to write and implement and I may have to accept that it won't look right on many browser windows.)

 
An easy solution is to wrap the menu in a relatively positioned element and centre that one. This way you can use auto margins to put the relatively positioned container in the horizontal centre and it will serve as coordinates for the absolutely positioned menu. I don't know how much you can manipulate the positions to make sure that the menu would be in the top left position of its container.

However, an even simpler solution is to use a CSS based dropdown menu solution, such as suckerfish dropdowns.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Vragabond:

Thank you for your suggestions. I tried wrapping something around the JavaScript but the JavaScript didn't execute. (I'm sure its because I did not do something right. As I said, I am not experienced at this.)

The suckerfish dropdown sample does not center the menus but has them to the left which is not better than what I have now. There is a whole paragraph about why it must use Left for positioning so I don't know where/how to change it.

But I appreciate your trying to help.
 
Suckerfish dropdowns can be positioned anywhere in the page you want them and do not rely on a silly calculated absolutely positioned dimensions. Additionally, the use a standard, semantic code that works on all browsers except for IE6 (and older) without any javascript, degrades nicely in older browsers and allows search bots to traverse the site. Something that your javascript menu most probably does not do.

I really suggest switching to a more modern method of creating your menu. If you really want to insist on this JS solution, maybe asking in forum216 would yield better results.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top