Make theme able to do Drop-Down menus
-
Alright, so this is the first time I’ve coded my own theme and I’m having a bit of trouble with having drop-down menus work on it – I wasn’t aware that this was something that I had to make the theme be able to do.
Anyway, so when I first tried adding a sub item when in appearance<menus and doing the indenting thing it would just add the sub category as a permanent link right under my main menu and shifting a bunch of content around.
So after looking around for a bit I ended up doing the following.Adding this to my functions.php file:
//Register Custom Menu's register_nav_menus( array( 'main' => 'main', 'secondary' => 'secondary', ) );And this to the header.php file, before the closing header div:
<div id="menu" class="menu-center"> <?php wp_nav_menu( array( 'theme_location' => 'main' ) ); ?> </div>And finally adding this CSS:
ul.menu,ul.menu ul,ul.menu li,ul.menu a { display:block; margin:0; padding:0; } ul.menu ul { display:none; } ul.menu li:hover { z-index:999; } ul.menu li:hover > ul { display:block; position:absolute; float:left; } ul.menu li { float:left; width:auto; } ul.menu ul li { float:center; width: 150px; margin-left: -40px; border-bottom:1px outset #a1a1a1; } ul.menu ul li ul { float:left; width:190px; position:absolute; left:100%; top:0; } ul.menu-ver,ul.menu-ver ul { width:14em; } div.menu-center ul.menu { float:left; position:relative; left:50%; } div.menu-center ul.menu li { position:relative; left:-50%; } div.menu-center ul.menu li li { left:auto; } ul.menu li a:link,ul.menu li a:hover,ul.menu li a:visited,ul.menu li a:active { text-decoration:none; } ul.menu li { filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='white', endColorstr='#000000',GradientType=0 ); background: white; } .menu-center { float:right; margin-right:95px; }After all of that, it didn’t even end up making it a vertical drop down, but instead it’s going vertically.
You can see it on my site here: dinaxdesign.com
So my questions is 1) Is this even the right code to be using?
and 2) If not, then what is? If yes, then how can I make it go down vertically instead?Thanks! I would really appreciate any help!!
-
You’re off to a good start.
In general, it may help to dial-back your expectations of WordPress. It can’t be everything for everybody and it’s not psychic — it has no way of knowing that you happen to want a drop-down menu.
I think you’ll get something closer to the look you’re wanting if you go
<style> #header ul.sub-menu li { float: none; </style>Haha, yeah I’m starting to get that – I’m just learning as I go.
But thanks! That was exactly what I was looking for 🙂
The topic ‘Make theme able to do Drop-Down menus’ is closed to new replies.