I’m creating my first WordPress theme. It’s a very simple one for a friend’s website, who is a music producer. I’m creating the navigation menu. One of the items on the menu is listen. It’s not an actual link. You hover over it and a submenu should appear. So I made Listen a custom link.
The problem is that the submenu doesn’t appear. The Submenu has its own class. But I don’t think WordPress is reading the CSS
Here is the CSS:
ul.sub-menu {
display: none;
position: absolute;
padding: 0px;
margin-left: -20px;
}
ul.sub-menu li {
display: block;
text-align: left;
background-color: grey;
}
ul.sub-menu li:hover {
background-color: #dae0e6;
}
ul.main_nav li:hover ul.sub-menu {
display: block;
}
Here is the HTML and php code in the header.php:
<nav>
<?php
$defaults = array(
'container' => false,
'theme_location' => 'primary-menu',
'menu_class' => 'main_nav'
);
wp_nav_menu( $defaults );
?>
<!--
<ul class="main_nav">
<li>
<a href="home.html">Home</a>
</li>
<li>
<a href="bio.html">Bio</a>
</li>
<li>
<a>Listen</a>
<ul class="sub-menu">
<li><a href="musicOriginal.html">Originals</a></li>
<li><a href="musicTvfilm.html">TV/Film</a></li>
</ul>
</li>
<li><a href="credits.html">Credits</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
-->
</nav>
Here is my approach:
I changed css so its shows menu sub menu with CSS.
JsFiddle Demo
In example above your menu is commented out. Also parent of ul.sub-menu should be positioned relative.
since you are new … I think you should start by get general idea about the sub menu and style them in WordPress .
this Tut will help you
http://wproots.com/how-to-style-wordpress-menus-dropdowns/
also I will suggest other option for you .
start form other theme like wordpress deafult theme and edit it
start form starter theme like
http://bootstrapwp.rachelbaker.me/
start from template
its hard to build theme from scratch if you are new … step by step
please assign width to ul like
and plaece
just after it