Click here to Skip to main content
15,887,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am stuck here unable to figure out on how to complete this drop down menu off mine and I thought I have got everything right? Could you experts please help? As I am a noob in web designs and have been stuck for the last few days. If you load the files to Jfiddle you would be able to see under the "Products & Services" tab that the links drop and spread across rather than dropping down? Please help.

Thanks

HTML

XML
<div id="menu">

<ul>

<font face="arial"><li><a title="Return to Home Page" href="index.html">Home</a></li>
<li><a title="Learn More About Us" href="about.html">About Us</a></li>
<li><a title="Products & Services" href="pands.html">Products & Services</a>
<ul>
<li><a href="#">Link Item</a></li>
<li><a href="#">Link Item</a></li>
<li><a href="#">Link Item</a></li>
<li><a href="#">Link Item</a></li>
<li><a href="#">Link Item</a></li>
<li><a href="#">Link Item</a></li>
</li>
</ul>
</li>
<li><a title="FAQs" href="faq.html">FAQs</a></li>
<li><a title="Contact Information" href="contact.html">Contact Us</a></li>
<li><a title="Reviews" href="feedback.html">Testimonials</a></li>

</ul>



CSS


CSS
#menu {width: 100%;
       height: 42px;
       clear: both;
       background: url(images/button_end_gradient.png) center left no-repeat;
       position: relative;}

#menu ul {list-style-type: none;
          margin: 0;
          padding: 0;
          position: absolute;
          left: 2px;
          background: #6A7A86 url(images/menu_background.png) repeat-x;
          color: #DCE0E4;}

#menu ul li {display: inline;}

#menu ul li a {text-decoration: none;
               height: 42px;
               padding: 0 17px;
               margin: 0;
               line-height: 42px;
               display: block;
               float: left; !important;
               background: url(images/button_end_gradient.png) center right no-repeat;
               color: #D8DCE0;
               font-size: 16px;
               font-weight: bold;}

#menu ul ul {
position:absolute;
visibility:hidden;
top:42px;
}

#menu ul li:hover ul {
visibility:visible;
}

#menu ul li a:hover {background: url(images/button_end_gradient.png) center right no-repeat;
                     color: #FFF;}
Posted

1 solution

The issue is in the sub-list inheriting the display inline and position attributes from the parent menu list and items.

One way to fix it is:
CSS
<pre lang="css">#menu {width: 100%;
       height: 42px;
       background: url(images/button_end_gradient.png) center left no-repeat;
       position:relative;}

#menu ul {list-style-type: none;
          margin: 0;
          padding: 0;
          position: absolute;
          display:block; /* explicitly require menu to be a block element */
          left: 2px;
          background: #6A7A86 url(images/menu_background.png) repeat-x;
          color: #DCE0E4;
          }

div#menu ul li {display:inline-block; /* list items are inline-blocks so their child items are kept within their boundaries */
position:relative; /* relative to allow sub-list to stay under parent list item */
}

#menu ul li a {text-decoration: none;
               height: 42px;
               padding: 0 17px;
               margin: 0;
               line-height: 42px;
               display: block;
               float: left; !important;
               background: url(images/button_end_gradient.png) center right no-repeat;
               color: #D8DCE0;
               font-size: 16px;
               font-weight: bold;}

#menu ul ul {
position:absolute;
visibility:hidden;
top:42px;
}

#menu ul li:hover ul {
visibility:visible;
}

#menu ul li a:hover {background: url(images/button_end_gradient.png) center right no-repeat;
                     color: #FFF;}</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900