Forum Moderators: not2easy
We have a list of categories for our store which are currently styled in a table using CSS for text properties and link properties (color change and underlining). We are trying to write this menu so that when a user hovers over an item the "text" itself will swap to some other text (i.e. the word "antipasto" turns to "appetizers" on hover).
I have seen a lot of suggestions to use images for the swap or even have the text disappear and display a background image with the second text and I'm not opposed to trying these options but I'd like to keep the menu as clean as possible and not have to create a ton of images each time our categories change.
Does anyone know if this is possible and could they point me in a direction? I have no problem researching and doing my homework on this so no freebies necessary - just looking for a "yes this can be done in CSS" and here's a place to start or "no it cannot be done in CSS". Thanks in advance and sorry if this forum isn't the right place for this question.
Thanks in advance!
Regards,
Joe
Welcome to WebmasterWorld.
There is a thread on this subject, but I do not remember where except it is under the CSS forum. Check the forum library. I do recall it has to do with putting a <span> in the <a> and the span is hidden on a:link and visible on a:hover. It's something like this:
<a href="whatever">LINK<span>Alt Text</span></a>
You can even assign exact positioning to the <span> too.
Off the top of my head, I cannot recall more specifics. Hope this helps.
Marshall
<style>
.switchable .alt {display:none}
.switchable:hover .default {display:none}
.switchable:hover .alt {display:inline}
</style>
<a href="#" class="switchable"><span class="default">Default Text</span><span class="alt">Alternative Text</span></a>
The above is tested in Firefox 1.5. The <a href=""> is used because that's the only element which Internet Explorer supports the :hover psuedoclass for. If you want to remove the underline and the colour, just add this to your style section:
.switchable {color:black;text-decoration:none}
I have been looking around this site - fantastic info out here I can't believe I didn't find you guys sooner! I'll take another look into the forum library as you suggested and also take a stab at the code with the suggestions you both gave.
I'll let you know what I find. Again - many thanks!
.switchableText {
font-family: Arial, sans-serif;
font-size: 12px;
text-transform: none;
color: #888785;
font-weight: 400;
text-indent: 10px;
line-height: 16px;
}
.switchableText .default {text-decoration: none; color: #888785;}
.switchableText .alt {display:none}
.switchableText:hover .default {display:none}
.switchableText:hover .alt {display:inline; text-decoration: underline; color: #234d9c;}
Default TextAlternative Text CSS is not really designed for this, you should either consider using Javascript to display the alternative text, or find a method which is semantically more comprehensible, at the very least separating the two versions of the link text - for example, two separate links, one positioned over the other.
So - I think I'll play around with my stylesheet for a bit and if I can't find the issue then it's off to JavaScript.
Funny about the browsers and SEO - I figured CSS would be the most compatible and most SEO friendly choice - that's why I was staying away form images with hover and trying to use just text wherever possible. Shouldn't this be the case?
There are many points of view on image vs. text links and I am sure it will be a debate that will never end, kind of like table vs. tableless layout. Regardless, IMHO, text links are better than images on so many levels:
1) SEO,
2) Download time,
3) Images that fail to download/browsers with images turned off,
4) Images are not necessarily fluid,
5) Accessibility,
6) and text is not at all confusing.
Need I say more.
Marshall
Thanks again!
--Joe
I've done my homework and built a nice little menu in JS which will swap text. It works great in all browsers. The kicker is this - I've done a lot "more" homework and am finding that having a JS based menu may be detrimental to one's customer base. Meaning if end users don't have JS enabled then they're stuck with nowhere to go. I'm posting this back in the CSS forum because after many hours of thinking, talking, and reading on-line CSS text menus seem to be the most failsafe way to go.
So my problem is that the CSS menu with the text swap works great in IE 7. In FireFox it swaps text but the underline is always present, in IE 6 it swaps but then sticks and won't swap back when the mouse is moved off and in Safari it doesn't swap at all and the underline is always present.
I know we're not supposed to post URL's in this site so I've tried to explain what's happening the best I can. I'm wondering if anyone could take a look at my CSS code and then my menu code and see if I'm doing something way wrong here. Or at least point me in a good starting direction. For this example I've changed one item in the menu, "Formaggio" which is supposed to swap to "Cheese" on mouse over.
Thanks in advance for any help!
CSS code:
.switchableText {
font-family: Arial, sans-serif;
font-size: 12px;
text-transform: none;
color: #888785;
font-weight: 400;
text-indent: 10px;
line-height: 16px;
}
.switchableText .default {text-decoration: none; color: #888785;}
.switchableText .alt {display:none}
.switchableText:hover .default {display:none}
.switchableText:hover .alt {display:inline; text-decoration: underline; color: #234d9c;}
HTML:
<tr>
<td colspan="3">
<a href="merchant.mvc?Screen=CTGY&Store_Code=CFF&Category_Code=cheese" class="switchableText"><span class="default">Formaggio</span><span class="alt">Cheese</span></a></td>
</tr>