473,765 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2334
Death Slaught
1,137 Top Contributor
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
3484
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 there is no drop down menu functionality at all. I wanted to implement an alternative stylesheet for IE, but my link to it is apparently broken. What is wrong with my link? I'd
2
2583
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 disappears). Is there a way, I can keep the menu always on top. ( A good example of what I'm looking for is similar to the menu bar in http://www.milonic.com/ ).
0
1842
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: http://msdn.microsoft.com/workshop/author/dhtml/howto/mousecaptureddm.asp How To Create a Mouse Capture Drop-down Menu (Internet Explorer) If not how?
1
2859
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 a bit of information on what i did if you want t read it. When I choose select an option in the drop down menu and hit submit, I increase a counter, and a 2nd loop generates a second drop down menu with the same options. This is exactly what...
1
1804
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 based in a table so the widths of the columns could be amended per column and they grew as the browser window grew and the entire menu width could be set to be exactly the same width as the banner heading (100% table width). I've now started to...
2
5255
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, but I am unable to store a variable for it. Here is a rough copy of what I am making: <html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
4
9296
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 if it works, and if it does not, tell me why it does not work. Thanks.
1
2764
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 other browsers. I have tried putting the swf elements on another layer and changing the Z order, but that doesn't work either. Any suggesetions? Do I need to change the menu to a swf too?
2
5677
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 background color and text alignment as the top level item. Am I asking too much of the asp:menu control? I went the "-CssClass" route in order to get my menu option text to center, but this does not seem to play well with the styling properties...
22
3467
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
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.