Submenu of a submenu HTML+CSS

703 views Asked by At

I'm tryning to create a submenu of a submenu but i can't figure out how to do.Right now i have a menu and a submenu1 that are working but i need to make another submenu2 of first submenu1 that appears only when "li" from submenu1 is hovered.

Fiddle : https://jsfiddle.net/buprgb6g/

CSS :

#divMenu ul, li, li li {
    margin: 0;
    padding: 0;
    z-index:2 !important;
}

#divMenu {
    width: 199px;
    height: auto;
}
#divMenu h3 {
    color: #fff;
    background-color: #25408f;
    padding: 10px 2px;
    text-align: center;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 12px;
    font-family: Verdana, Geneva, sans-serif;
}
#divMenu ul {
    line-height: 25px;
}
#divMenu li {
    list-style: none;
    position: relative;
    background: #dedfe0;
}
#divMenu li li {
    list-style: none;
    position: relative;
    background: #dedfe0;
    left: 199px;
    top: -27px;
}
#divMenu ul li a {
    width: 189px;
    height: auto;
    display: block;
    text-decoration: none;
    text-align: left;
    color: #25408f;
    padding-left:5px;
    padding-right:5px;
    text-transform: uppercase;
    border: 1px solid #eee;
    font-size: 10px;
    font-weight: bold;
    font-family: Verdana, Geneva, sans-serif;
}
#divMenu ul ul {
    position: absolute;
    visibility: hidden;
    top: 27px;
}
#divMenu ul li:hover ul {
    visibility: visible;
}
#divMenu li:hover {
    background-color: #25408f;
    color: #fff;
}
#divMenu li:hover a {
    color: #fff;
}
#divMenu ul li:hover ul li a {
    color: #25408f !important;
    width: 285px;
}
#divMenu ul li:hover ul li a:hover {
    background-color: #25408f !important;
    color: #fff !important;
}
#divMenu a:hover {
    font-weight: bold;
}

HTML

<div id="divMenu">
  <h3>TEST</h3>
  <ul>
    <li><a href="#">GROUP A</a>
      <ul>
        <li><a href="#">PRODUCT 1</a></li>
        <li><a href="#">PRODUCT 2</a></li>
      </ul>
    </li>
    <li><a href="#">GROUP B</a>
      <ul>
        <li><a href="#">PRODUCT 1</a></li>
        <li><a href="#">PRODUCT 1</a></li>
      </ul>
    </li>
  </ul>
</div>

And this is the HTML i want to work :

<div id="divMenu">
  <h3>TEST</h3>
  <ul>
    <li><a href="#">GROUP A</a>
      <ul>
        <li><a href="#">PRODUCT 1</a>
          <ul>
            <li>PRODUCT 1 A</li>
            <li>PRODUCT 1 B</li>
          </ul>
        </li>
        <li><a href="#">PRODUCT 2</a>
          <ul>
            <li>PRODUCT 2 A</li>
            <li>PRODUCT 2 B</li>
          </ul>
        </li>
      </ul>
    </li>
    <li><a href="#">GROUP B</a>
      <ul>
        <li><a href="#">PRODUCT 1</a></li>
        <li><a href="#">PRODUCT 1</a></li>
      </ul>
    </li>
  </ul>
</div>
2

There are 2 answers

0
shihab mm On BEST ANSWER

Remove width

#divMenu ul li:hover ul li a {
  color: #25408f !important;
  width: 285px; //Remove this width.
}

Change css from

#divMenu ul li:hover ul {
  visibility: visible;
}

To

#divMenu ul li:hover > ul {
  visibility: visible;
}

Done It will work fine.

0
bugkiller On

When you specify a selector without specifying a nested child, the style cascades into other child elements as well.

you need to specify the nested child using the > operator, that would solve it.

for instance:

#divMenu ul li:hover ul {

should be changed to:#divMenu ul li:hover > ul {