/    Sign up×
Community /Pin to ProfileBookmark

a {..} and a:link {…}

Hi,
I would just like to know what’s the difference between the two syntax stated on the title. Is there any difference if I use [B]a[/B] or [B]a:link[/B]?

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJun 25.2007 — The colon denotes a pseudo class. In the case of a link, it represents the different states a link can be in: link (unclicked, unvisited, and not in focus or hovered on); visited (visited, unclicked, not in focus, and not hovered on); active (clicked); hover (mouse is over the link); focus (the system focus is on the link). Without the colon, you are styling all <a> tags in general:
a {
font-weight: bold;
}

a:hover {
font-style: italic;
}

In the code above, all <a> tags would be boldface. But only when you hover over an <a> tag would it turn italisized:
[code=html]<a name="menu">Menu</a><br>
<a href="home.html">Home</a>[/code]


You generally want to specify your link styles in this order:
a:link {}
a:visited {}
a:hover {}
a:focus {}
a:active {}

The order the styles appear is important. Consider this bit of code:
a:link {}
a:hover {}
a:visited {}

Since the :hover state is defined before the :visited state, the :visited state over-rules the :hover state. In this case, you could hover your mouse over a visited link, and the hover styles won't show. So be careful of the order in which you define link styles.
Copy linkTweet thisAlerts:
@webStruck_authorJun 25.2007 — so, if i am to use like

[CODE]a
{font-weight: bold;}[/CODE]


and

[CODE]a:link
{font-weight: bold;}[/CODE]



does no difference between the two? it reads the same general unvisited, unhovered, and inactive anchored link?
Copy linkTweet thisAlerts:
@ryanbutlerJun 25.2007 — Not quite...a{} would give [B]ALL[/B] links in your website a font weight of bold. a:link describes a behavior...meaning you could have links in certain places that didn't exhibit a font weight of bold, whereas others could. On the surface they seem to mean the same in concept and theory, but they're not.
Copy linkTweet thisAlerts:
@webStruck_authorJun 26.2007 — i'm confused. is there any example that implements the functionality of each of the anchors? or simply how do i use those, and when?
Copy linkTweet thisAlerts:
@toicontienJun 26.2007 — My first post shows you how. The link psuedo classes are a tad confusing at first, but make sense when you take a step back. Here's a link to get you started:

http://www.w3schools.com/css/css_pseudo_classes.asp
Copy linkTweet thisAlerts:
@CentauriJun 26.2007 — Clarification and simplification maybe required....

a {..} will target all <a> tags, whether they are just anchors or links (<a href>) and all states of links (ie, :link, :visited, :active, :hover)

a:link {..} will only target links , and only unvisited, unactive, unhovered links - those other states will default to their normal styling unless explicity styled otherwise.

Therefore, if you wanted to remove the text-decoration from all links, whether they have been visited or being hovered etc, use the base a [COLOR="Blue"]{ text-decoration: none;}[/COLOR]

Clear as mud?

Cheers

Graeme
Copy linkTweet thisAlerts:
@webStruck_authorJun 29.2007 — CLEAR AS MUD.

Thanks Centauri. you're the best!
×

Success!

Help @webStruck_ 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 4.28,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...