2013-11-23 104 views
1

大家好! 我正在为我自己的网站创建一个wordpress模板,我需要一个下拉多级菜单。我管理wordpress输出第一个子菜单级别作为“子菜单”,第二个子菜单作为“子子菜单”。但我需要分别访问每个子子菜单。我试过:第一胎或:第n个孩子(X),在以下方面:CSS选择子菜单

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

但它们也都没有奏效。这里是我的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"> 
        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> 

链接jsfiddle

回答

2

要定位第一.sub-sub-menu你可以使用:

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

而对于第二:

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

Demo

+0

非常感谢,这工作。 – sveatlo