Maksim
Maksim

Reputation: 16931

CSS Hyperlink for any text

Question for CSS designers. How do I add anchor behavior to any css class without "<a href.." attribute. Here is what I mean.

I'm going to have this html code:

<span class="my_link">LINK TO SOMETHING </span>

and this text should have link behavior (visited color, active color and underlining, "pointing hand pointer").

Is it possible to make this in css?

Upvotes: 0

Views: 881

Answers (3)

Tyler Carter
Tyler Carter

Reputation: 61557

Unless you put it in an tag, you can not get the visited, active, etc colors without javascript. You can however get the pointing hand cursor, and the ability for it to go somewhere when you click on it. To make it have the correct pointer use this:

.my_link{ cursor: pointer; }

and for the clicking, use.

$(".my_link.").click(function(){
location.href="page";
}

Upvotes: 1

meder omuraliev
meder omuraliev

Reputation: 186562

span.my_link { text-decoration:underline; cursor:pointer; }

You could make use of :hover if you want to apply hover styles to it. Though I'm really not sure why you can't use an anchor.

Upvotes: 3

Isaac Waller
Isaac Waller

Reputation: 32730

The visited and active color will have to be done in Javascript. The pointer and underline can be done like this:

.my_link { cursor: pointer; text-decoration: underline; }

Upvotes: 1

Related Questions