Hey everyone! I'm currently in the process of designing a WordPress template for my personal website, and I require assistance with creating a dropdown multilevel menu. So far, I have successfully configured WordPress to display the first submenu level as "sub-menu" and the second level as "sub-sub-menu". However, I am struggling to target each individual sub-sub-menu separately. I attempted using :first-child or :nth-child(x), like this:
.sub-sub-menu:nth-child(2) { /*this targets both sub-sub-menus*/
background: red;
}
.sub-sub-menu:nth-child(1) { /*but doesn't work*/
background: red;
}
Unfortunately, neither of these methods proved successful. Below is the code generated by WordPress:
<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">
Sub-Subpage 1
</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">
Sub-Subpage 2
</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">
Subpage 2
</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">
Sub-Subpage 1
</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>
You can access the JSFiddle link here.