I’ve created a very simple plugin for creating and adding dropdown menus to your page. In this simple step-by-step tutorial i will try to explain how to create your own theme with simple css edits. All you need to do is to follow those simple steps and you will have one great css-only dropdown with colors you like!
1 First we need to set default theme to NONE for the dropdown menu. You can do that from the “Dropdown Menu” item under your WordPress Settings.
2 Then open your theme stylesheet from Appearance -> Editor. Make sure your current theme is selected. Select Stylesheet from Styles and scroll to the bottom of the file. You can add a reminder using /* and */ slashes as in the image. We will create our css rules after this line.
3 Dropdown menu css tree is defined in following way.
.shailan-dropdown-menu -> main container of the menu (div element) ul.dropdown -> top list ul.dropdown li -> top list item + sub items (refers to <li> elements under <ul>) ul.dropdown li a -> menu links ul.dropdown li ul -> sub lists
4 First we add a background image to top level using the .shailan-dropdown-menu class:
.shailan-dropdown-menu { background:#000000 url("your-image-here.jpg") top right repeat; }
“#000″ defines background color to be black. Look here for more html color codes. Your background image should be in your theme directory. Otherwise you should put a full url like “http://shailan.com/sample.jpg”. Other k-words define positioning and repeating of background. Visit here for more info on background.
5 Second most important thing on the menu style is the link style:
.shailan-dropdown-menu ul.dropdown li a {
padding: 5px 15px;
font-size: 1em;
color:#ffffff; }
Here we defined top-bottom (5px) and right-left (15px) padding values. And we set color to white.
6 Now let’s define the mouse over style for the links:
.shailan-dropdown-menu ul.dropdown li a:hover {
font-style: italic;
background-color:#ffffff;
color:#333333; }
This rule defines that when we move mouse over (hover) a link (< a > element in html) it will have white (#ffffff) background color and text will be a dark gray (#333333). Text will become italic also.
7 One more additional style will be dropdown background:
.shailan-dropdown-menu ul.dropdown li ul{ width:auto; background:#333333; background: url(images/opacity.png);
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-khtml-border-radius: 4px; }
This is a rather complex rule. This rule defines background for the dropdown menu’s when you move over a link. Here we set it to have a gray(#333333) background. Then we put a background image to it. Transparent pixels don’t work in older Internet Explorer browsers. You should get Google chrome really if you are still using IE. Here we also add corner radius which is also not supported by Internet Explorer.
8 The last style rule comes for the current page or category link. If you want current page or category seem different than other links add following:
.shailan-dropdown-menu ul.dropdown li.current_page_item>a,
.shailan-dropdown-menu ul.dropdown li.current-cat>a,
.shailan-dropdown-menu ul.dropdown li.current-cat>a:hover,
.shailan-dropdown-menu ul.dropdown li.current_page_item>a:hover{
color:#333333;
background: white; }
This will make your current page/category have a white background with dark gray text.
9 Now to wrap it up here is the final code:
/* MY-DROPDOWN-STYLES */
.shailan-dropdown-menu { background:#000000 url("your-image-here.jpg") top right repeat; }
.shailan-dropdown-menu ul.dropdown li a {
padding: 5px 15px;
font-size: 1em;
color:#ffffff; }
.shailan-dropdown-menu ul.dropdown li a:hover {
font-style: italic;
background-color:#ffffff;
color:#333333; }
.shailan-dropdown-menu ul.dropdown li ul{ width:auto; background:#333333; background: url(images/opacity.png);
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-khtml-border-radius: 4px; }
.shailan-dropdown-menu ul.dropdown li.current_page_item>a,
.shailan-dropdown-menu ul.dropdown li.current-cat>a,
.shailan-dropdown-menu ul.dropdown li.current-cat>a:hover,
.shailan-dropdown-menu ul.dropdown li.current_page_item>a:hover{
color:#333333;
background: white; }
And we are done!
Conclusion
Now that you know how to create a simple dropdown menu style, you can download the widget and start building your own menu theme!


Is there a selector for the current li/page item’s parent menu – Is there a way to style the current top menu item instead of (or in addition to) the specific child page within the drop down?
Something like:
.shailan-dropdown-menu li.current_page_item>a{
}
Thanks.
Awesome plugin!
Yes, this is supported with wordpress page navigations. The selector is:
ul.dropdown li.current_page_parent a{ /* CSS */ }Thanks for the reply! That selector seems to however style all subsequent children as well. Am I missing something?
You need to revert sub children using sub selector:
ul.dropdown li.current_page_parent li a{ /* CSS */ }Actually you can use “>” but this only works on modern browsers.
It won’t work in many Internet Explorer versions.
IE makes us take the long way like this.
I hate IE :/
Hi, I am having problems setting it up:
I want this dropdown menu to replace my current menu on http://kunstnerblog.simtanda.com/
I know i have to place this code in my template.
But wich template and wich line?
Hello Hans, I see you are using twentyten as a theme. You can switch your theme to twentyeleven theme i created, and you will have a widget area just below the header. Get latest version here.
Hi Shailan,
What will I change with this code if I want a click before the dropdown rather than a mouse hover? Your widget and codes are very helpful. Thanks.
Hey, Shailan!
Very nice plugin, thank you very much!
Would suggest adding of new templates to be a bit more flexible? Now you hard-code all ones shipped in shailan-dropdown-menu-options.php, so if I wish to add mine css it won’t be automatically visible. If I edit the php, changes will get lost on the next update, etc,
I’d suggest just scan the themes directory for the css files and get their pretty names from some properly formatted comment at the top, just like WP does with themes.
Cheers!
Alex
Is there any way I can make the drop down gallery be a drop up gallery? for example if the navigation was bellow the content and slides up when rolled over…
Yes you can do this using Custom CSS area.
Just put this code in there:
ul.dropdown li ul{ top: auto !important; bottom: 100% !important; }This should do it.
First of all, thank you for creating this widget, although, How can I get the menu to be on one line or get the theme to follow the menu into the 2nd line? Does this make sense?
Love the plugin, I have it all styled the way I wanted it but lost the current_page_item class when I switched the menu to the custom menu I created in WordPress.
In other words if I don’t chose the menu type for pages or category there’s no css class for the active or current page with a custom menu.
Any suggestions would be great. I’m very familiar with css and WordPress so I should be able to follow your suggestions without trouble, thank you.
I just noticed how to fix my issue, sorry … I saw there was another class current-menu-item that showed up instead. Targeting that class worked perfect.
Great plugin. Very easy to use. Thanks so much for making it.
I have a question.. Is there any way to make the 2nd level drop down go straight down instead of off to the right?
Thx again for a great plugin.
Please disregard my question.. Obviously there was something else wrong with my site.. Plugin works perfectly now..