I am trying to make a javascript drop-down navigation menu for my first
rails web site, and I am having some problems with where the menu list
divs pop up on the page.
What I have is a horizontal menu bar with headings (the headings are
links to the home page of each section), and then lists of the pages
within that same section are supposed to appear directly underneath
their heading when you hover over the heading. Pretty standard stuff.
All of the effects and everything are working great, the only problem I
am having is that the divs that hold the page lists pop up about 50px
farther down and also to the right than I expected, so that they are far
away from the header. This is a really big problem because the menu
disappears when your cursor exits the header, so you never have time to
click on anything in the dropdown menu!
Now, there’s just one more catch:
I ran into a bug with getting my menus to disappear at first, so I found
the solution on another site that makes all of the effects work. But
that code places the div off of the page to the left using CSS, and then
uses JavaScript to bring the div back into view, so… No, I cannot use
CSS to position the div, I have to change the JavaScript.
Ok, so here’s the code:
/* HTML for the headers & menus*/
/JavaScript for hiding/showing menus/
/* Navigation menu style*/ #tabbar { margin: 0px 20px 0px 20px; padding: 0px 0px 0px 0px; text-align: left; display: block; width: 760px; vertical-align: bottom; background-color:#000000; } #tabbarbox { margin: 0 auto; padding: 7px 0 0 0; width: 760px; background: rgb(231,231,231) url("images/tabbar.jpg") no-repeat bottom center; vertical-align: bottom; } .tab, .tabselected { display: table-cell; text-align: center; height: 22px; padding: 0px 2px 0px 2px; margin: 0px 0px 0px 0px; vertical-align: middle; } #tabbar a { display: table-cell; text-align: center; height: 22px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; vertical-align: middle; } .tabbar_button_l { display: table-cell; vertical-align: middle; } .tabbar_button_c { margin: 0 7px 0 7px; padding: 2px 0 2px 0; vertical-align: middle; } .tab .tabbar_button_l { background: transparent url(images/tab_unselected_left.jpg) no-repeat top left; } .tab .tabbar_button_c { background: transparent url(images/tab_unselected_central.jpg) repeat-x top; } .tab .tabbar_button_r { background: transparent url(images/tab_unselected_right.jpg) no-repeat top right; } .tabselected .tabbar_button_l { background: transparent url(images/tab_left.jpg) no-repeat top left; } .tabselected .tabbar_button_c { background: transparent url(images/tab_central.jpg) repeat-x top; } .tabselected .tabbar_button_r { background: transparent url(images/tab_right.jpg) no-repeat top right; } .amenu { position: absolute; left: -999em; margin: 25px 0px 0px 2px; padding: 5px 5px 5px 5px; border: 1px solid #A2A2A2; background-color: #E6E6E6; min-width: 88px; text-align: left; } .amenu ul{ padding:0; margin:0px 0px 0px 17px; } .amenu ul li { display: list-item; list-style-type: none; margin: 0; padding: 0; vertical-align: middle; } .amenu ul ul{ padding: 0; margin: 0px 0px 0px 10px; } .amenu:hover{ left: 0em; } /* IE Hack */ .grouphover { left: 0em; }Sorry, I don’t have a live preview, but hopefully I gave enough info in
this super-long post. =)
I’m sure the answer is not too complicated, as I learned the JavaScript
from online tutorials, and I’m probably just not familiar with the
solution.
Thanks a million in advance for any help guys!