Which is correct ?

liunx

Guest
Hi,

I've been using this to colour my links etc.:

<style type="text/css" media="screen">
<!--
a.leftlink:link {
color: #0000FF;
background-color: #FFFFFF;
}
a.leftlink:visited {
color: #990000;
background-color: #FFFFFF;
}
etc.................

and then in the body:

<div>
<p><a class="leftlink" href=http://www.webdeveloper.com/forum/archive/index.php/"#">Hello</a></p>
<p><a class="leftlink" href=http://www.webdeveloper.com/forum/archive/index.php/"#">Goodbye</a></p>
<p><a class="leftlink" href=http://www.webdeveloper.com/forum/archive/index.php/"#">Hi</a></p>
</div>

However I've also used this which I have now been told is incorrect:

<style type="text/css" media="screen">
<!--

.rightlink a:link {
color: #0000FF;
background-color: #FFFccc;
}
.rightlink a:visited {
color: #990000;
background-color: #FFFccc;
}

etc....................

and in the body:

<div class="rightlink">
<p><a href=http://www.webdeveloper.com/forum/archive/index.php/"#">Hello</a></p>
<p><a href=http://www.webdeveloper.com/forum/archive/index.php/"#">Goodbye</a></p>
<p><a href=http://www.webdeveloper.com/forum/archive/index.php/"#">Hi</a></p>
</div>

The point being that in the second version there is a lot less code especially if there are a lot of links as you can just set the class in the div.

In the first version the class has to be put in every anchor tag.

I've been told that the first version is the correct way to code but the second version seems much neater to me and seems to work in current browsers.

Is there a problem in coding it this way? I've had a look at W3c and their example is like the first version. Any advice would be welcome.

PaulOriginally posted by Paul O'B
However I've also used this which I have now been told is incorrect:


Whoever told you that doesn't know what he's talking about. Tell that person to first visit <!-- w --><a class="postlink" href="http://www.w3.org">www.w3.org</a><!-- w --> and check the specs instead of making things up :rolleyes:

The second way is something I also use a lot, for the exact same reason you mention, it's a lot less coding.
It's not only correct to do it, it's also the smart way. :)Thanks Stefan,

Perhaps I'm not as stupid as I thought :D

I shall carry on using the second method , thanks for your help.

Paul
 
Back
Top