What are you trying to accomplish, that you think you need to move the current_page_item class from the list item to the anchor?
Why can’t you just target the anchor like this?
.current_list_item a {
/* style definitions go here */
}
Thread Starter
daebat
(@daebat)
I’m trying to accomplish background images applied to active menu items. For example… Menu item two is menu_02.jpg. Easy enough with this code:
ul.sf-menu li.page-item-2 a{
background:url(images/menu_02.jpg) 0 0 no-repeat transparent;
width:156px;
height:43px;
text-indent: 9999px;
line-height:0;
font-size:0;
}
Now I’d like for the image to change if active… so the code (provided the current_page_item class was moved below to the link) would work from this CSS:
ul.sf-menu li.page-item-2 a.current_page_item {
background:url(images/menu-active_02.jpg) 0 0 no-repeat transparent;
width:156px;
height:43px;
text-indent: 9999px;
line-height:0;
font-size:0;
}
If I were to use your code it would apply the same background image to ALL of my menu items. The design I was sent does not have web friendly fonts so this is why I am using images instead of text (although the text is there, just indented -9999 px.)
HERE IS MY PAGE: http://honyat.com/steph/
have you tried the logical approach of css:
ul.sf-menu li.page-item-2.current_page_item a { ... }
Thread Starter
daebat
(@daebat)
holy crap! I didn’t realize you could combine same level classes like that. Thank you soooooooo much Alchymyth!
Use this for your CSS for list items:
ul.sf-menu li.page-item-2 a{
background:url(images/menu_02.jpg) 0 0 no-repeat transparent;
width:156px;
height:43px;
text-indent: 9999px;
line-height:0;
font-size:0;
}
Now, use this declaration for the current list item:
ul.sf-menu li.page-item-2.current_page_item a {
background:url(images/menu-active_02.jpg) 0 0 no-repeat transparent;
width:156px;
height:43px;
text-indent: 9999px;
line-height:0;
font-size:0;
}
See how you can stack classes on the same element? The li.page-item-2.current_list_item selector will have higher specificity than the li.page-item-2 selector, and thus will override it.
alchymith beat me to the punch. 🙂