0

HTML code

.navbar li {
  color: #B7B7B7;
  font-family: 'Montserrat', sans-serif;
  font-size: 14px;
  min-width: 70px;
  padding: 22px 16px 18px;
}
.navbar #menumain ul {
  width: 120%;
}
.navbar ul ul {
  display: none;
}
<div class="navbar">
  <li id="menumain">
    Menu1main
    <ul>
      <a href="/">
        <li>Menu2</li>
      </a>
    </ul>
  </li>
</div>

How to change display:none in navbar ul ul to display:block with :hover How to change display:none in navbar ul ul to display:block with :hover ?

2
  • can you add your code to jsfiddle? Commented Oct 4, 2016 at 6:44
  • Li elements must be child of ul/ol, not div Commented Oct 4, 2016 at 6:47

4 Answers 4

2

I'm guessing what you're asking for is something like this:

.navbar li:hover ul {
    display: block;
}

But your code is not clear. You currently have .navbar ul ul in your selector, but you don't have two nested uls anywhere in your markup.

Sign up to request clarification or add additional context in comments.

Comments

2
.navbar li:hover ul {
    display: block;
}

I guess you mean this

EDIT: @David Hedlund You were faster

Comments

0

You may try writing the :hover with your div class.

.navbar li:hover ul {
    display: block;
}

According to your HTML code, you do not have 2 ul instead 1 li and 1 ul. Ideally it should be ul first and then li in HTML code.

Comments

0

You are doing wrong man. a>li is a bad practice. you need to do li>a

.navbar > li > ul { display: none; }
.navbar > li:hover > ul { display: block; }
<div class="navbar">
  <li id="menumain">
    Menu1main
    <ul>
      <li><a href="/">item1</a></li>
      <li><a href="/">item2</a></li>
    </ul>
  </li>
</div>

Remember HTML W3C Validator Error: Element a not allowed as child of element ul in this context. (Suppressing further errors from this subtree.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.