1

everybody! I'm creating a wordpress template for my own website and I need a dropdown multilevel menu. I've managed wordpress to output the first submenu level as "sub-menu" and the second as "sub-sub-menu". But I need to access each of the sub-sub-menus individually. I tried the :first-child or :nth-child(x), in following context:

.sub-sub-menu:nth-child(2) { /*selects both sub-sub-menus*/
    background: red;
}
.sub-sub-menu:nth-child(1) { /*doesnt work*/
    background: red;
}

But neither one of them worked. Here is my wordpress-generated code:

<section id="menu">
  <div id="menu_container" class="menu-header_menu-container">
    <ul id="menu-header_menu" class="menu">
      <li id="menu-item-26" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-26">
        <a href="http://localhost/wordpress">
          Home
        </a>
      </li>
      <li id="menu-item-162" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current_page_ancestor menu-item-162">
        <a href="http://localhost/wordpress/?page_id=136">
          Page 1
        </a>
        <ul class="sub-menu">
          <li id="menu-item-193" class="menu-item menu-item-type-post_type menu-item-object-page current-page-ancestor current-menu-ancestor current-menu-parent current-page-parent current_page_parent current_page_ancestor menu-item-193">
            <a href="http://localhost/wordpress/?page_id=192">
              subpage 1
            </a>
            <ul class="sub-sub-menu">
              <li id="menu-item-200" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-200">
                <a href="http://localhost/wordpress/?page_id=196">
                  subsubpage1
                </a>
              </li>
              <li id="menu-item-209" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-209">
                <a href="http://localhost/wordpress/?page_id=204">
                  subsubpage2
                </a>
              </li>
            </ul>
          </li>
          <li id="menu-item-188" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-188">
            <a href="http://localhost/wordpress/?page_id=187">
              subapge2
            </a>
            <ul class="sub-sub-menu">
              <li id="menu-item-217" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-217">
                <a href="http://localhost/wordpress/?page_id=214">
                    subsubpage1
                </a>
              </li>
            </ul>
          </li>
        </ul>
      </li>
      <li id="menu-item-161" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-161">
        <a href="http://localhost/wordpress/?page_id=138">
         Page 2
        </a>
      </li>
      <li id="menu-item-168" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-168">
        <a href="http://localhost/wordpress/?page_id=167">
          Page 3
        </a>
      </li>
      <li id="menu-item-172" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-172">
        <a href="http://localhost/wordpress/?page_id=171">
          Page 4
        </a>
      </li>
    </ul>
  </div>
</section>

Link to jsfiddle

1 Answer 1

2

To target the first .sub-sub-menu you can use:

.sub-menu .menu-item:nth-child(1) .sub-sub-menu {
    background: red;
}

And for the second:

.sub-menu .menu-item:nth-child(2) .sub-sub-menu {
    background: red;
}

Demo

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

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.