links with css

liunx

Guest
hi<br />
<br />
please could you guide me through the syntax for setting class id's for links.i know the normal routine for setting the links for the whole page but i need to use the id attribute...<br />
<br />
<STYLE type="text/css"><br />
<!-- <br />
<br />
#skins { font-family: arial; font-size: 20; font-style: bold; color: red }<br />
#mains { A:link-color: red; A:visited-color: green }<br />
--><br />
<br />
</STYLE> <br />
<br />
<a ID="mains" href=http://www.htmlforums.com/archive/index.php/"matts.html">Matts Page</a><br />
<p ID="skins">paragraph goes here</p> <br />
<br />
the skins bit works but not the links<br />
<br />
thanks<br />
<br />
DaFunk<!--content-->There are a couple of workarounds for this. First, you could just define the overall styles for all Anchor tags:<br />
<br />
<html><br />
<head><title>blah</title><br />
<style type="text/css"><br />
A:link{ color:red; }<br />
A:visited { color:green; }<br />
#skins { font-family: arial; font-size: 20; font-style: bold; color: red; } <br />
</style><br />
</head><br />
<body bgcolor="#ffffff" text="#000000" id=all topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"><br />
<a href=http://www.htmlforums.com/archive/index.php/"matts.html">Matts Page</a> <br />
<p ID="skins">paragraph goes here</p> <br />
</body><br />
</html><br />
<br />
By defining the overall styles for all links, it won't be necessary to include an ID in the actual <a href> tag.<br />
<br />
However, if you need more flexibility for your link colors (e.g. you have set all links to color: red, and you need to display a link in a <td> with a bgcolor of red), you can override the style for all links by including an ID (defining the color) for that link specifically...<br />
<br />
<html><br />
<head><title>blah</title><br />
<style type="text/css"><br />
A:link{ color:red; }<br />
A:visited { color:green; }<br />
#skins { font-family: arial; font-size: 20; font-style: bold; color: red; } <br />
#white { color: white; }<br />
</style><br />
</head><br />
<body bgcolor="#ffffff" text="#000000" id=all topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"><br />
<table border=0><br />
<tr><br />
<td bgcolor="red"><br />
<a href=http://www.htmlforums.com/archive/index.php/"matts.html" id="white">Matts Page</a> <br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<p ID="skins">paragraph goes here</p> <br />
</td></tr><br />
</table><br />
</body><br />
</html><br />
<br />
The above will work for all color attributes of the link, (color)will stay the same for visited AND active links.<br />
<br />
I hope this was useful to you.<br />
<br />
Sillyfish<!--content-->I think what you are after is class (.class).<br />
If you define a class it can be assigned to one or more tags in your page. This way all the links belonging to the (white) group you simply give class="white" in the tag, and the others you want to be red should have class="red" in the tag. Using ID's should only be used for INDIVIDUAL elements which will not be repeated throughout the page.<br />
<br />
<html><br />
<head><br />
<style type="text/css"><br />
A.white:link {color: white; background-color: red;}<br />
A.white:visited {color: black; background-color: red;}<br />
A.white:active {color: yellow; background-color: blue;}<br />
A.white:hover {color: white; background-color: blue;}<br />
<br />
A.red:link {color: red; background-color: white;}<br />
A.red:visited {color: brown; background-color: white;}<br />
A.red:active {color: black; background-color: red;}<br />
A.red:hover {color: white; background-color: red;}<br />
</style><br />
</head><br />
<body><br />
<a href=http://www.htmlforums.com/archive/index.php/"somepage.html" class="white">Hi there</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"somepage.html" class="red">Hi there</a><br />
</body><br />
</html><br />
<br />
Alternatively you can set up a standard class and simply define the differences as needed, eg<br />
<br />
.white {font-family: arial,verdana; font-size 14pt;}<br />
A.white:hover {color: white; }<br />
A.white:visited {color: yellow;}<br />
A.white: active {color: orange;}<br />
A.white:hover { color: red;}<!--content-->While sillyfish is corrrect, he/she has avoided the question. Setting class ID's is very simple. And its nice because you can have different links do different things instead of setting a global parameter for all links.<br />
In the HEAD section plac ecode like this:<br />
<br />
<STYLE type="text/css"><br />
<!--<br />
a {color: blue; text-decoration: none}<br />
a:hover {color: red; text-decoration: overline underline}<br />
a.class1 {color: blue; text-decoration: none}<br />
a.class2 {color: purple; text-decoration:none}<br />
a.links {color: #E7BD00; text-decoration: underline; font-size: 10pt; font-family: Arial;}<br />
--><br />
</STYLE><br />
<br />
then in the body just reffer to the class ID for any links:<br />
<br />
<A class=class1 href=http://www.htmlforums.com/archive/index.php/"http://www.yahoo.com">Yahoo</a><br><br />
<A class=class1 href=http://www.htmlforums.com/archive/index.php/"http://www.msn.com">MSN</a><BR><br />
<A class=class1 href=http://www.htmlforums.com/archive/index.php/"http://www.exite.com">Exite</a><br><br />
<A class=class2 href=http://www.htmlforums.com/archive/index.php/"http://www.altavista.com">Altavista</a><br><br />
<A class=class2 href=http://www.htmlforums.com/archive/index.php/"http://www.infoseek.com">Infoseek</a><br><br />
<A class=class2 href=http://www.htmlforums.com/archive/index.php/"http://www.hotbot.com">Hotbot</a><br><br />
<br />
<br />
Regards,<br />
Kevin<!--content-->Interesting response and nice insight kevin and kdj... I hadn't considered implementing a class for links as shown by the both of you. This will no doubt make life much easier. Thanks for the input!<br />
<br />
-Sillyfish<!--content-->yeah that works fine in msie but what about that old dog netscape..<br />
<br />
take a look i might be doing something wrong<br />
<br />
<!-- m --><a class="postlink" href="http://www.dreamwater.org/mattsplace/index.html">http://www.dreamwater.org/mattsplace/index.html</a><!-- m --><br />
<br />
if you use msie first and then netscape you will notice the difference. Select code from the main page<br />
<br />
Wouldnt it be wonderful if browsers read html and css the same way. <br />
<br />
so how do i have different coloured links in netscape<br />
cheers <br />
<br />
DaFunk<!--content-->
 
Back
Top