How can I make a link visible only when one hovers over the link?
views:
328answers:
3
+3
A:
Try this:
a:link, a:visited {
visibility: hidden;
}
a:link:hover, a:visited:hover {
visibility: visible;
}
Edit After piquadrat pointed out that Firefox doesn’t hover invisible elements, try this instead:
a:link span, a:visited span {
visibility: hidden;
}
a:link:hover span, a:visited:hover span {
visibility: visible;
}
And the corresponding HTML:
Lorem <a href="foo"><span>foo</span></a> ipsum dolor sit amet …
Gumbo
2009-09-24 21:22:14
Could I set the hover option dynamically via jquery?
mrblah
2009-09-24 21:25:26
@homestead, The `:hover` pseudoselector can't be 'set' in Javascript as far as I know (in a standard way, anyway). You could make a class `hover` and use that.
strager
2009-09-24 21:28:25
@homestead: Sure: `$("head")[0].append('<style type="text/css"> … </style>')`
Gumbo
2009-09-24 21:29:25
could I possibly change the class of the element on the fly that would make it visible upon hover? (doing it on certain elements under certain conditions, that's why I need to do it dynamically)
mrblah
2009-09-24 21:30:18
@homestead: Well than add a class selector to the selector of the CSS rules.
Gumbo
2009-09-24 21:31:40
gumbo, sorry I don't follow you... add a class selector to the selector?
mrblah
2009-09-24 21:40:09
@homestead: Use `a.class:link, a.class:visited` instead and add your elements to that class.
Gumbo
2009-09-24 21:41:45
+2
A:
Did you mean you'd like the link to appear like normal text?
If so:
a { text-decoration: none; color: inherit; }
a:hover, a:active { text-decoration: underline; color: #00F; }
ceejayoz
2009-09-24 21:34:59
+2
A:
The answers that used visibility
CSS rule don't work for me, at least not in FF. The link is not visible, so when you move the mouse over it FF thinks you are hovering over whatever is behind the link.
This works for me though (even in IE6!):
a {
zoom: 1; filter: alpha(opacity = 0); /* For IE */
opacity: 0.0;
}
a:hover {
zoom: 1; filter: alpha(opacity = 100); /* For IE */
opacity: 1.0;
}
Kip
2009-09-24 21:43:12
After reading `visibility` didn't work I immediately thought of using `opacity` like in your answer. +1. Note: the `zoom` and `filter` are needed only for IE6 (and below?) and not for IE7 or IE8 (as far as I know).
strager
2009-09-24 22:37:12
@strager: actually zoom/filter is still needed on IE8. (I just tested it to make sure)
Kip
2009-09-25 01:23:55