How do I underline parent menu item but not children?

Posted by Steven on Stack Overflow See other posts from Stack Overflow or by Steven
Published on 2012-04-10T11:17:43Z Indexed on 2012/04/10 11:28 UTC
Read the original article Hit count: 477

Filed under:
|

Using Wordpress menu "builder", I get the following code:

  //Pseaudo code

  <ul id="main-menu-main">
    <li class="menu-item"><a></a></li>
    <li class="menu-item current-menu-ancestor">
      <a></a>
      <ul class="sub-menu">
        <li class="menu-item"><a></a></li>
        <li class="menu-item current-menu-item"><a></a></li>
      </ul>
    </li>
  </ul>


  // and I use the following CSS 
  #menu-main-menu a:hover { text-decoration: underline; }
  #menu-main-menu .current-menu-ancestor a { text-decoration: underline; }

The problem with my last css line, is that all a elements under current-menu-ancestor are underlined. I only want the link in current-menu-ancestor to be underlined.

I think this should be pretty simple, but right now my head is not focused :-/

The full code for parent / child looks like this:

<ul id="menu-main-menu" class="menu">
  <li id="menu-item-401" class="menu-item-first 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-401">
  <a>menu 1</a>    
  <ul class="sub-menu">
    <li id="menu-item-444" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-415 current_page_item menu-item-444">
    <a> sub 1</a>
    </li>
  </ul>
</li>

© Stack Overflow or respective owner

Related posts about css

Related posts about Wordpress