开发者

How to get dropdown Jquery navigation menu to expand over web page elements [Basic]

I know this is a pretty basic question, but I don't know how to articulate what I want into a Google search to solve my problem.

I am working on a website for a Non-profit, and I am currently using Jquery and CSS to create a dynamic dropdown navigation bar. The code + examples can be found here: http://designreviver.com/tutorials/jquery-css-example-dropdown-menu/

The Nav menu works great, however when the elements expand, the new content forces the rest of the content on the page to move down and it messes up the entire formatting of the site. Most websites usually just have the Nav bar elements expand OVER the rest of the page without modifying locations...

here is the example code of what I am using:

<ul id="cssdropdown">
<li class="headlink">
    <a href="mine.html?search_engines">Search Engines</a>
     <ul>
      <li><a href="http://google.com/">Google</a></li>
      <li><a href="http://yahoo.com/">Yahoo</a></li>
      <li><a href="http://live.com/">Live Search</a></li>
     </ul>
     </li>
      <li class="headlink">
      <a href="mine.html?shopping">Shopping</a>
         <ul>
      <li><a href="http://amazon.com/">Amazon</a></li>
      <li><a href="http://ebay.com/">eBay</a></li>
      <li><a href="http://craigslist.com/">CraigsList</a></li>
     </ul>
 </li>
</ul>

Then for the CSS:

   li.headlink ul { display: none; }
   li.headlink:hover ul { display: block; }

Does anyone have any insight about what I might be doing wrong?

Thank you!

Da开发者_StackOverflowve


If your markup permits, e.g., your menu is at the top of your page, absolutely position the menu.

#cssdropdown {position:absolute}

View the example on jsFiddle


have you tried putting a float on li.headLink like below? It seems to be caused by not floating your menu items.

li.headlink { float:left }


try changing this line

li.headlink:hover ul { display: block; }

into this

li.headlink:hover ul { display: block; position:absolute; }


It might be that wrapper div that's causing it. My original solution should work if you remove it. You could also try the solution from Juventus18 but also add:

li.headlink { position: relative }

so your code will be:

li.headlink { position: relative }
li.headlink:hover ul { display: block; position:absolute; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜