Advertisement
askwpcoach

Style WordPress menus (with subs)

Nov 19th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.66 KB | None | 0 0
  1. #nav    {
  2.     height: 30px; /* set to the height you want your menu to be */
  3.     margin: 0 0 10px; /* just to give some spacing */
  4. }
  5. #nav ul {
  6.     margin: 0; padding: 0; /* only needed if you have not done a CSS reset */
  7. }
  8. #nav li {
  9.     display: block;
  10.     float: left;
  11.     line-height: 30px; /* this should be the same as your #main-nav height */
  12.     height: 30px; /* this should be the same as your #main-nav height */
  13.     margin: 0; padding: 0; /* only needed if you don't have a reset */
  14.     position: relative; /* this is needed in order to position sub menus */
  15. }
  16. #nav li a   {
  17.     display: block;
  18.     height: 30px;
  19.     line-height: 30px;
  20.     padding: 0 15px;
  21. }
  22. #nav .current-menu-item a, #main-nav .current_page_item a, #main-nav a:hover {
  23.     color: #000;
  24.     background: #ccc;
  25. }
  26.  
  27. #nav ul ul { /* this targets all sub menus */
  28.     display: none; /* hide all sub menus from view */
  29.     position: absolute;
  30.     top: 30px; /* this should be the same height as the top level menu -- height + padding + borders */
  31. }
  32. #nav ul ul li { /* this targets all submenu items */
  33.     float: none; /* overwriting our float up above */
  34.     width: 150px; /* set to the width you want your sub menus to be. This needs to match the value we set below */
  35. }
  36. #nav ul ul li a { /* target all sub menu item links */
  37.     padding: 5px 10px; /* give our sub menu links a nice button feel */
  38. }
  39.  
  40. #nav ul li:hover > ul {
  41.     display: block; /* show sub menus when hovering over a parent */
  42. }
  43. #nav ul ul li ul {
  44.     /* target all second, third, and deeper level sub menus */
  45.     left: 150px; /* this needs to match the sub menu width set above -- width + padding + borders */
  46.     top: 0; /* this ensures the sub menu starts in line with its parent item */
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement