By quicksand on
Hello everbody,
In order to use images instead of texts in my menus, i'm trying to add span tags to links, like this :
<li class="first active-trail"><a href="blabla"><span>MyLink</span></a>
Then with CSS, i do this :
li.active-trail a span {
display:none
}
and i give a background to a
i've tried this with no succes in my template.php
<?php
function mytheme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' '. $extra_class;
}
if ($in_active_trail) {
$class .= ' active-trail';
}
return '<li class="'. $class .'">'. '<span>'.$link.'</span>' . $menu ."</li>\n";
}
?>
in this code, span tags are around a tags.
How can i do ?
Thanks
Comments
No span required
You don't need a span for this. Simply set the anchor text to
text-indent: -999em;(or px if you prefer) which is the preferred method for CSS image replacement. If you setoverflow: hidden;as well you can avoid some cases where the browser does its dotted clicked-link thing that expands far to the left when using this method.Here's a code snippet I wrote in another post which might help illustrate (as well as a rollover effect for the image):
On a separate note though, you likely need to clear the menu cache if you are adding the code you show above. But in this case I'd advise against it, as it's quite possible to avoid delving into the PHP in this case.
Thanks for this solution. But
Thanks for this solution.
But little difficult, because i'm using Nice Menus module, i want to replace only parents items by images, but children must stay in text.
The problem : When i apply
text-ident:-999emandoverflow:hidden, the text disapear in the parent item and also in children items.I think, there's no solution in CSS to reset the text-ident to normal ?
Thanks
Try this
I had a look at Nice Menus... try this, which should reset the child level of the menu. It's possible you might have to do it again if you have a third/etc level. Just follow the same pattern if that's the case.
and...
**Edit, saw you solved it as well :)
Okay, Solved ! Juste for the
Okay, Solved !
Juste for the children items, i do this
text-ident:0px;Thanks
text-indent
Unfortunately, text-indent doesn't work very well. it doesn't work in some browsers for cross browser compatibility.
Anyone know of a way to add a span with drupal?
EDIT: Just ended having to modify the menu-block.tpl.php file.
Text-indent works in all browsers
Text-indent works in all browsers... not sure what you're referring to. Which browser do you feel has an issue?
See: http://reference.sitepoint.com/css/text-indent