Skip to content Skip to sidebar Skip to footer

Cannot Make Menubar Dropdown Hover Properly

I have a menu bar which has 8 to 9 menus horizontally of different character length. Also, each and every menu has sub menus of different character length. All I want is - 1. a

Solution 1:

There is jsfiddle example toked from CSS Menu Maker site

I made some little changes to simplify example. Little update, nothing special

Update (fiddle too):

<div id='cssmenu'>
  <ul>
     <li><a href="#">Product Repository </a>
    <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">File Upload</a></li>
    </ul>
</li>
<li><a href="#">Inventory Inspection</a>
    <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">Reprint</a></li>
        <li><a href="#">Inventory Report</a></li>
    </ul>
</li>
<li><a href="#">Reports</a>
    <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
    </ul>
</li>   
  </ul>
</div>

and css :

        #cssmenu {padding: 0; margin: 0; border: 0;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding: 0;}
#cssmenu ul {position: relative; z-index: 597; }
#cssmenu ul li { float: left; min-height: 1px; vertical-align: middle; border:solid 1px blue; width:150px;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 599; cursor: default; background-color:yellow;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 150px;}
#cssmenu ul ul li {float: none; margin-left:-1px; width:150px; border:solid 1px red;}
#cssmenu ul li:hover > ul { visibility: visible;}
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0; }
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; /*line-height: 1em;*/ text-decoration: none; }

It's not pretty but You can see the point.

Update (code changed):

#cssmenu
{
    padding:0;
    margin:0;
    display:block;
}
a {text-decoration:none; color:black; width:100%; box-sizing:border-box; display:block;}
#cssmenu ul
{
  position:relative;
  margin:0;
  padding:0;
  cursor:default;
  display:table;
  width:100%;
  border:solid 1px gray;
}
#cssmenu ul li, #cssmenu ul li:last-child
{
  list-style-type:none;
  display:table-cell;
  text-align:center;
  vertical-align:middle;
  padding-top:3px;
  padding-bottom:3px;
  border-right:solid 1px gray;
  margin:0;
  position:relative;
}
#cssmenu ul li:last-child {border:none;}
#cssmenu ul li:hover {background-color:yellow;}
#cssmenu ul li:hover > a {color: red;}
#cssmenu ul ul
{
  visibility:hidden;
  position:absolute;
  top:100%;
  margin:0;
  margin-left:-1px;
  z-index:101;
  display:block;
}
#cssmenu ul ul li, #cssmenu ul ul li:last-child
{
    display:block;
    width:100%;
    box-sizing:border-box;
	border:none;
	border-bottom:solid 1px gray;
}
#cssmenu ul ul li:last-child {border:none;}
#cssmenu ul ul li:hover
{
  background-color:navy;
}
#cssmenu ul li li:hover > a {color:white;}
#cssmenu ul li:hover > ul {visibility:visible;}
<div id='cssmenu'>
  <ul>
     <li><a href="#">Product Repository </a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">File Upload</a></li>
      </ul>
     </li>
     <li><a href="#">Inventory Inspection</a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">Reprint</a></li>
        <li><a href="#">Inventory Report</a></li>
      </ul>
    </li>
    <li><a href="#">Reports</a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
      </ul>
    </li>   
    <li><a href="#">Product Repository </a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">File Upload</a></li>
      </ul>
    </li>
    <li><a href="#">Inventory Inspection</a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">Reprint</a></li>
        <li><a href="#">Inventory Report</a></li>
      </ul>
    </li>
    <li><a href="#">Reports</a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
      </ul>
    </li>   
    <li><a href="#">Product Repository </a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">File Upload</a></li>
      </ul>
    </li>
    <li><a href="#">Inventory Inspection</a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
        <li><a href="#">Reprint</a></li>
        <li><a href="#">Inventory Report</a></li>
      </ul>
    </li>
    <li><a href="#">Product Repository </a>
      <ul>
        <li><a href="#">Insert</a></li>
        <li><a href="#">Search & Edit</a></li>
      </ul>
    </li>   
   </ul>
</div>

Try this solution, but when You Run code snippet switch it to Full Page. I hope so this is what You want. But, always but, if Your window is too small, You can't avoid item values in two rows.


Post a Comment for "Cannot Make Menubar Dropdown Hover Properly"