/    Sign up×
Community /Pin to ProfileBookmark

Which is correct ?

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=”#”>Hello</a></p>
<p><a class=”leftlink” href=”#”>Goodbye</a></p>
<p><a class=”leftlink” href=”#”>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=”#”>Hello</a></p>
<p><a href=”#”>Goodbye</a></p>
<p><a href=”#”>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.

Paul

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@StefanJan 21.2003 — [i]Originally posted by Paul O'B [/i]

However I've also used this which I have now been told is incorrect:
[/QUOTE]


Whoever told you that doesn't know what he's talking about. Tell that person to first visit www.w3.org 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. ?
Copy linkTweet thisAlerts:
@Paul_O_BauthorJan 21.2003 — Thanks Stefan,

Perhaps I'm not as stupid as I thought ?

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

Paul
×

Success!

Help @Paul_O_B spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...