I'm creating my own wordpress theme and I took help from this link to create a drop-down submenu.
The problem is while hovering over the navigation menu, I want the submenu to appear like this-
and it looks like this originally -
and after hovering it looks like this -
How to rectify this so that the height of the top level menu stays as it is and the submenu appears like the one in the first image?
The code is given below- CSS:
.site-nav ul ul
{
display: none;
}
.site-nav ul li:hover > ul {
display: block;
}
Wordpress HTML + PHP code
<nav class="site-nav">
<?php
$args=array(
'theme_location' => 'primary',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => my_nav_wrap(),
'depth' => 2,
'walker' => ''
);
?>
<?php wp_nav_menu($args); ?>
</nav>
This is the rendered HTML code :
<nav class="site-nav">
<div class="menu-cf-menu-test-container">
<ul id="menu-cf-menu-test" class="menu">
<li id="menu-item-1561" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1553 current_page_item menu-item-1561">
<a href="http://localhost/wordpress/?page_id=1553">Home</a>
</li>
<li id="menu-item-1243" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1243">
<a href="http://localhost/wordpress/?page_id=1220">About</a>
</li>
<li id="menu-item-1535" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1535">
<a href="http://localhost/wordpress/?page_id=1214">Program Implementation</a>
</li>
<li id="menu-item-1283" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1283">
<a href="#">Register</a>
</li>
<li id="menu-item-1536" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1536">
<a href="http://localhost/wordpress/?page_id=1371">Login</a>
</li>
<li class="menu-item-has-children">
<a href="/profile">Hi sid!</a>
<ul class="sub-menu">
<li>
<a href="/profile">View Profile</a>
</li>
<li>
<a href="/logout">Logout</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>