473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to create drop down menu vertically using html and css?

Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2. /* Root = Horizontal, Secondary = Vertical */
  3. ul#navmenu-h {
  4.   margin: 0;
  5.   border: 0 none;
  6.   padding: 0;
  7.   width: 600px; /*For KHTML*/
  8.   list-style: none;
  9. }
  10.  
  11. ul#navmenu-h li {
  12.     margin: 0;
  13.     border: 0 none;
  14.     padding: 0;
  15.     float: left; /*For Gecko*/
  16.     display: inline;
  17.     list-style: none;
  18.     position: relative;
  19.     width: 185px;  
  20.  
  21. }
  22.  
  23.  
  24. ul#navmenu-h ul {
  25.   margin: 0;
  26.   border: 0 none;
  27.   padding: 0;
  28.   width: 600px;
  29.   list-style: none;
  30.   display: none;
  31.   position: absolute;
  32.   top: 24px;
  33.   left: 0;
  34.  
  35. }
  36.  
  37. ul#navmenu-h ul:after /*From IE 7 lack of compliance*/{
  38.   clear: both;
  39.   display: block;
  40.   font: 1px/0px serif;
  41.   content: ".";
  42.   height: 0;
  43.   visibility: hidden;
  44. }
  45.  
  46. ul#navmenu-h ul li {
  47.   width: 300px;
  48.  
  49.   float: left; /*For IE 7 lack of compliance*/
  50.   display: block !important;
  51.   display: inline; /*For IE*/
  52. }
  53.  
  54. /* Root Menu */
  55. ul#navmenu-h a {
  56.   border: 1px solid #FFF;
  57.   border-right-color: #D6C7A7;
  58.   border-bottom-color: #D6C7A7;
  59.   text-align:left;
  60.   padding: 0 6px;
  61.   float: none !important; /*For Opera*/
  62.   float: left; /*For IE*/
  63.   display: block;
  64.   background: #F1ECE1;
  65.   color: #666;
  66.   font: bold 10px/22px Verdana, Arial, Helvetica, sans-serif;
  67.   text-decoration: none;
  68.   height: auto !important;
  69.   height: 1%; /*For IE*/
  70. }
  71.  
  72. /* Root Menu Hover Persistence */
  73. ul#navmenu-h a:hover,
  74. ul#navmenu-h li:hover a,
  75. ul#navmenu-h li.iehover a {
  76.   background: #D6C7A7;
  77.   color: #FFF;
  78.     text-align:left;
  79.  
  80. }
  81.  
  82. /* 2nd Menu */
  83. ul#navmenu-h li:hover li a,
  84. ul#navmenu-h li.iehover li a {
  85.   float: none;
  86.   background: #F1ECE1;
  87.   color: #666;
  88.  
  89.  
  90.  
  91. }
  92.  
  93. /* 2nd Menu Hover Persistence */
  94. ul#navmenu-h li:hover li a:hover,
  95. ul#navmenu-h li:hover li:hover a,
  96. ul#navmenu-h li.iehover li a:hover,
  97. ul#navmenu-h li.iehover li.iehover a {
  98.   background: #D6C7A7;
  99.   color: #FFF;
  100. }
  101.  
  102. /* 3rd Menu */
  103. ul#navmenu-h li:hover li:hover li a,
  104. ul#navmenu-h li.iehover li.iehover li a {
  105.   background: #F1ECE1;
  106.   color: #666;
  107. }
  108.  
  109. /* 3rd Menu Hover Persistence */
  110. ul#navmenu-h li:hover li:hover li a:hover,
  111. ul#navmenu-h li:hover li:hover li:hover a,
  112. ul#navmenu-h li.iehover li.iehover li a:hover,
  113. ul#navmenu-h li.iehover li.iehover li.iehover a {
  114.   background: #D6C7A7;
  115.   color: #FFF;
  116. }
  117.  
  118. /* 4th Menu */
  119. ul#navmenu-h li:hover li:hover li:hover li a,
  120. ul#navmenu-h li.iehover li.iehover li.iehover li a {
  121.   background: #F1ECE1;
  122.   color: #666;
  123. }
  124.  
  125. /* 4th Menu Hover */
  126. ul#navmenu-h li:hover li:hover li:hover li a:hover,
  127. ul#navmenu-h li.iehover li.iehover li.iehover li a:hover {
  128.   background: #D6C7A7;
  129.   color: #FFF;
  130. }
  131.  
  132. ul#navmenu-h ul ul,
  133. ul#navmenu-h ul ul ul {
  134.   display: none;
  135.   position: absolute;
  136.   top: 0;
  137.   left: 160px;
  138. }
  139.  
  140. /* Do Not Move - Must Come Before display:block for Gecko */
  141. ul#navmenu-h li:hover ul ul,
  142. ul#navmenu-h li:hover ul ul ul,
  143. ul#navmenu-h li.iehover ul ul,
  144. ul#navmenu-h li.iehover ul ul ul {
  145.   display: none;
  146. }
  147.  
  148. ul#navmenu-h li:hover ul,
  149. ul#navmenu-h ul li:hover ul,
  150. ul#navmenu-h ul ul li:hover ul,
  151. ul#navmenu-h li.iehover ul,
  152. ul#navmenu-h ul li.iehover ul,
  153. ul#navmenu-h ul ul li.iehover ul {
  154.   display: block;
  155. }
  156.  
  157. </style>
  158.  
  159. <script type="text/javascript">
  160. navHover = function() {
  161.     var lis = document.getElementById("navmenu-h").getElementsByTagName("LI");
  162.     for (var i=0; i<lis.length; i++) {
  163.         lis[i].onmouseover=function() {
  164.             this.className+=" iehover";
  165.         }
  166.         lis[i].onmouseout=function() {
  167.             this.className=this.className.replace(new RegExp(" iehover\\b"), "");
  168.         }
  169.     }
  170. }
  171. if (window.attachEvent) window.attachEvent("onload", navHover);</script>
  172.  
  173.  
  174.  
  175.   <table width="100%" border="0" cellspacing="0" cellpadding="0">
  176.     <tr>
  177.       <td align="center" valign="top"> <ul id="navmenu-h">
  178.  
  179.     <li><a href="#"> home &raquo;</a>
  180.         <ul> <li><a href="#">abc</a>
  181.  
  182.           <a href="#">pqr</a>         
  183.            <a href="#">Top  REVIEW sites  &raquo;</a>
  184.  
  185.           </li>
  186.            </li> 
  187.  
  188.         </ul>
  189.     </li>
  190.  
  191.   </ul></td>
  192.     </tr>
  193.     <tr>
  194.       <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  195.         <tr>
  196.           <td width="20%" align="left" valign="top">&nbsp;</td>
  197.           <td width="80%" align="left" valign="top"><form name="form1" method="post" action="">
  198.  
  199.  
  200.                     </form>
  201.           </td>
  202.         </tr>
  203.       </table></td>
  204.     </tr>
  205.     <tr>
  206.       <td align="center" valign="top">&nbsp;</td>
  207.     </tr>
  208.   </table>
Nov 10 '10 #1
1 2323
Death Slaught
1,137 1GB
What problem are you having, what browser are you having it in, what have you tried to do to fix it. Please remember to give information about the problem when posting questions.

The links in your sub menu each need to be in their own list element.


Expand|Select|Wrap|Line Numbers
  1.     <li><a href="#"> home &raquo;</a>
  2.         <ul>
  3.             <li><a href="#">abc</a></li>
  4.             <li><a href="#">pqr</a></li>       
  5.             <li><a href="#">Top  REVIEW sites  &raquo;</a></li>
  6.  
  7.            </li> 
  8.  
  9.         </ul>
  10.     </li>

This does create a positioning issue, but I don't have time to look at it right now.


Thanks, Death
Nov 10 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Haines Brown | last post by:
I've implemented the horizontal drop down menu discussed recently in this newsgroup, and it works nicely under Galeon and Mozilla, but not IE 5.0. Here are the problems: Under IE 5.0, the...
2
by: hemanth.singamsetty | last post by:
Hello there, I've a drop down menu (created using CSS & Javascript -- see code below). My problem is, whenever I click a link on the menu the new page replaces the current page (and the menu...
0
by: Empire City | last post by:
Regarding the top menu 'Home Consulting Download' menu at http://www.4birckhead.com Is that drop-down menu done using the techniques explained at: ...
1
by: phpnewb | last post by:
Hi, I know i'm doing it wrong, but I'm using a while loop right now to create several instances of a drop down menu. It gives me undesirable results. Can you tell me the right way to do it. Below are...
1
by: OonaghG | last post by:
I have got a basic drop down menu written using CSS (complete with moving highlight & functioning dropdown where needed) but I have a couple of problems. 1. The original (non-dropdown) menu was...
2
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu,...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
1
by: tina1223 | last post by:
I have a Javascript drop down menu in an html page which views fine in Safari & Firefox, but in IE the drop downs are cut off by the swf elements on the page which they appear over top of fine in the...
2
by: Steve Richter | last post by:
I would like to have a standard site navigation menu, horizontal across the page, at the top of the page. When I hover over a top level menu item I want a drop down menu to appear with the same...
22
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.