Posted By

jonkemp on 07/29/10


Tagged

css javascript html


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jonhenshaw
michellebracken
manjarco
batandwacolani


Son of Suckerfish


 / Published in: HTML
 

URL: http://www.htmldog.com/articles/suckerfish/dropdowns/

Dropdown menus with pure HTML and CSS, with a JavaScript fallback for Internet Explorer 6. This version is more accessible, even lighter in weight (just 12 lines of JavaScript), have greater compatibility (they now work in Opera and Safari without a hack in sight) and can have multiple-levels.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Son of Suckerfish</title>
  5. <style type="text/css">
  6. #nav, #nav ul {
  7. padding: 0;
  8. margin: 0;
  9. list-style: none;
  10. line-height: 1;
  11. }
  12.  
  13. #nav a {
  14. display: block;
  15. width: 10em;
  16. }
  17.  
  18. #nav li {
  19. float: left;
  20. width: 10em;
  21. }
  22. #nav li ul {
  23. position: absolute;
  24. width: 10em;
  25. left: -999em;
  26. }
  27. #nav li:hover ul, #nav li.sfhover ul {
  28. left: auto;
  29. }
  30. <script type="text/javascript">
  31. sfHover = function() {
  32. var sfEls = document.getElementById("nav").getElementsByTagName("LI");
  33. for (var i=0; i<sfEls.length; i++) {
  34. sfEls[i].onmouseover=function() {
  35. this.className+=" sfhover";
  36. }
  37. sfEls[i].onmouseout=function() {
  38. this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
  39. }
  40. }
  41. }
  42. if (window.attachEvent) window.attachEvent("onload", sfHover);
  43.  
  44. </head>
  45.  
  46.  
  47. <ul id="nav">
  48. <li><a href="#" title="Course">COURSE</a>
  49. <ul>
  50. <li><a href="#" title="appetizers">appetizers</a></li>
  51. <li><a href="#" title="beverages">beverages</a></li>
  52. <li><a href="#" title="breads">breads</a></li>
  53. <li><a href="#" title="breakfast">breakfast</a></li>
  54. <li><a href="#" title="condiments">condiments</a></li>
  55. <li><a href="#" title="desserts">desserts</a></li>
  56. <li><a href="#" title="lunch/snacks">lunch/snacks</a></li>
  57. <li><a href="#" title="main dish">main dish</a></li>
  58. <li><a href="#" title="salads">salads</a></li>
  59. <li><a href="#" title="side dishes">side dishes</a></li>
  60. <li><a href="#" title="soups">soups</a></li>
  61. </ul>
  62. </li>
  63. <li><a href="#" title="Ingredient">INGREDIENT</a>
  64. <ul>
  65. <li><a href="#" title="appetizers">appetizers</a></li>
  66. <li><a href="#" title="beverages">beverages</a></li>
  67. <li><a href="#" title="breads">breads</a></li>
  68. <li><a href="#" title="breakfast">breakfast</a></li>
  69. <li><a href="#" title="condiments">condiments</a></li>
  70. <li><a href="#" title="desserts">desserts</a></li>
  71. <li><a href="#" title="lunch/snacks">lunch/snacks</a></li>
  72. <li><a href="#" title="main dish">main dish</a></li>
  73. <li><a href="#" title="salads">salads</a></li>
  74. <li><a href="#" title="side dishes">side dishes</a></li>
  75. <li><a href="#" title="soups">soups</a></li>
  76. </ul>
  77. </li>
  78. <li><a href="#" title="Cuisine">CUISINE</a>
  79. <ul>
  80. <li><a href="#" title="appetizers">appetizers</a></li>
  81. <li><a href="#" title="beverages">beverages</a></li>
  82. <li><a href="#" title="breads">breads</a></li>
  83. <li><a href="#" title="breakfast">breakfast</a></li>
  84. <li><a href="#" title="condiments">condiments</a></li>
  85. <li><a href="#" title="desserts">desserts</a></li>
  86. <li><a href="#" title="lunch/snacks">lunch/snacks</a></li>
  87. <li><a href="#" title="main dish">main dish</a></li>
  88. <li><a href="#" title="salads">salads</a></li>
  89. <li><a href="#" title="side dishes">side dishes</a></li>
  90. <li><a href="#" title="soups">soups</a></li>
  91. </ul>
  92. </li>
  93. <li><a href="#" title="Diet">DIET</a>
  94. <ul>
  95. <li><a href="#" title="appetizers">appetizers</a></li>
  96. <li><a href="#" title="beverages">beverages</a></li>
  97. <li><a href="#" title="breads">breads</a></li>
  98. <li><a href="#" title="breakfast">breakfast</a></li>
  99. <li><a href="#" title="condiments">condiments</a></li>
  100. <li><a href="#" title="desserts">desserts</a></li>
  101. <li><a href="#" title="lunch/snacks">lunch/snacks</a></li>
  102. <li><a href="#" title="main dish">main dish</a></li>
  103. <li><a href="#" title="salads">salads</a></li>
  104. <li><a href="#" title="side dishes">side dishes</a></li>
  105. <li><a href="#" title="soups">soups</a></li>
  106. </ul>
  107. </li>
  108. <li><a href="#" title="Occasion">OCCASION</a>
  109. <ul>
  110. <li><a href="#" title="appetizers">appetizers</a></li>
  111. <li><a href="#" title="beverages">beverages</a></li>
  112. <li><a href="#" title="breads">breads</a></li>
  113. <li><a href="#" title="breakfast">breakfast</a></li>
  114. <li><a href="#" title="condiments">condiments</a></li>
  115. <li><a href="#" title="desserts">desserts</a></li>
  116. <li><a href="#" title="lunch/snacks">lunch/snacks</a></li>
  117. <li><a href="#" title="main dish">main dish</a></li>
  118. <li><a href="#" title="salads">salads</a></li>
  119. <li><a href="#" title="side dishes">side dishes</a></li>
  120. <li><a href="#" title="soups">soups</a></li>
  121. </ul>
  122. </li>
  123. <li><a href="#" title="Preperation">PREPERATION</a>
  124. <ul>
  125. <li><a href="#" title="appetizers">appetizers</a></li>
  126. <li><a href="#" title="beverages">beverages</a></li>
  127. <li><a href="#" title="breads">breads</a></li>
  128. <li><a href="#" title="breakfast">breakfast</a></li>
  129. <li><a href="#" title="condiments">condiments</a></li>
  130. <li><a href="#" title="desserts">desserts</a></li>
  131. <li><a href="#" title="lunch/snacks">lunch/snacks</a></li>
  132. <li><a href="#" title="main dish">main dish</a></li>
  133. <li><a href="#" title="salads">salads</a></li>
  134. <li><a href="#" title="side dishes">side dishes</a></li>
  135. <li><a href="#" title="soups">soups</a></li>
  136. </ul>
  137. </li>
  138. </ul>
  139.  
  140. </body>
  141. </html>

Report this snippet  

You need to login to post a comment.