user2710234
user2710234

Reputation: 3225

CSS Menu not showing sub items

I have this css code for a menu:

/** CUSTOMER MENU **/
#CustomerMenu {
    margin-bottom:10px;
}
#CustomerMenu ul {
    padding: 0;
    margin:0 auto 0 auto;
    list-style-type: none;
    text-align: center;
    display:inline;
}
#CustomerMenu ul li {
    display: inline;
}
#CustomerMenu ul li a {
    text-decoration: none;
    padding: 10px;
    color: #FFFFFF;
    background-color: #666666;
}
#CustomerMenu ul li a:hover {
    color: #fff;
    background-color: #f36f25;
}
/** CUSTOMER MENU **/

but its not showing the sub items - fiddle below:

http://jsfiddle.net/dvborqgm/

Upvotes: 1

Views: 119

Answers (2)

Swapnil Motewar
Swapnil Motewar

Reputation: 1088

You have to use :hover and style for :hover on outer li

The submenu must be having position absolute and li as relative.

Following link provides help to create menu using css

http://www.wikihow.com/Create-a-Dropdown-Menu-in-HTML-and-CSS

Sample menu for your reference

body {
  font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  padding: 20px 50px 150px;
  font-size: 13px;
  text-align: center;
  background: #E3CAA1;
}

ul {
  text-align: left;
  display: inline;
  margin: 0;
  padding: 15px 4px 17px 0;
  list-style: none;
  -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
ul li {
  font: bold 12px/18px sans-serif;
  display: inline-block;
  margin-right: -4px;
  position: relative;
  padding: 15px 20px;
  background: #fff;
  cursor: pointer;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -ms-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
}
ul li:hover {
  background: #555;
  color: #fff;
}
ul li ul {
  padding: 0;
  position: absolute;
  top: 48px;
  left: 0;
  width: 150px;
  -webkit-box-shadow: none;
  -moz-box-shadow: none;
  box-shadow: none;
  display: none;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.2s;
  -moz-transition: opacity 0.2s;
  -ms-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  -transition: opacity 0.2s;
}
ul li ul li { 
  background: #555; 
  display: block; 
  color: #fff;
  text-shadow: 0 -1px 0 #000;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
}
<ul><li>Home</li>
  <li>About</li>
  <li>
    Portfolio
    <ul>
      <li>Web Design</li>
      <li>Web Development</li>
      <li>Illustrations</li>
    </ul>
  </li>
  <li>Blog</li>
  <li>Contact</li>
</ul>

Upvotes: 0

Mdk
Mdk

Reputation: 512

Here's a quick fix: http://jsfiddle.net/0781wtqu/ Basically, add a class to the submenus ("submenu" in my example) and hide it through a CSS rule, then add another CSS rule to show the hidden class when hovering

#CustomerMenu ul li:hover > ul.submenu { display: block; }

Upvotes: 2

Related Questions