Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link colors 1

Status
Not open for further replies.

horev

Programmer
Feb 17, 2006
18
0
0
IL
Hi !
I can decide what colours would my links be using the "body" tag, "link" "alink" and "vlink" attributes.
What if i want each link to have different colours ? Is it possible to do in HTML ?
Thanks !
 
Usinng CSS it is. I'd advise not using the body attributes, favouring CSS for all links:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="content-language" content="en">
	<title>Link colour demo</title>

	<style type="text/css">
		/* Style all links a default colour */
		a, a:link			{ color: #0000FF; }
		a:visited			{ color: #FF00FF; }
		a:hover				{ color: #FF0000; }
		a:active, a:focus	{ color: #00FF00; }

		/* Override some other link behaviour */
		.redLinksContainer a, .redLinksContainer a:link		{ color: #FF0000; }
		a.blueLink, a.blueLink:link							{ color: #0000FF; }
		a.greenLink, a.greenLink:link						{ color: #00FF00; }
	</style>
</head>

<body>
	<div>
		<a href="[URL unfurl="true"]http://www.google.co.uk/">Go[/URL] to Google</a><br />
		<a href="[URL unfurl="true"]http://www.yahoo.co.uk/">Go[/URL] to Yahoo!</a>
	<div>
	<div class="redLinksContainer">
		<a href="[URL unfurl="true"]http://www.google.co.uk/">Go[/URL] to Google</a><br />
		<a href="[URL unfurl="true"]http://www.yahoo.co.uk/">Go[/URL] to Yahoo!</a>
	</div>
	<div>
		<a class="blueLink" href="[URL unfurl="true"]http://www.google.co.uk/">Go[/URL] to Google</a><br />
		<a class="greenLink" href="[URL unfurl="true"]http://www.yahoo.co.uk/">Go[/URL] to Yahoo!</a>
	</div>
</body>
</html>

That's not a perfect example, as I've not overriden certain pseudo-classes for some links, but you get the idea.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top