Order of visited, link, active, hover

B

Ben Amada

I've seen some posts where it was said that when defining the styles for
links, "visited", "link", "active" and "hover" must be defined in a certain
order. However, I've seen these defined in 2 or 3 different orders. My
question is (A) does order really matter? and (B), if order does matter,
what is the correct order?

Thanks in advance,
Ben
 
M

Mark Parnell

I've seen some posts where it was said that when defining the styles for
links, "visited", "link", "active" and "hover" must be defined in a certain
order. However, I've seen these defined in 2 or 3 different orders. My
question is (A) does order really matter? and (B), if order does matter,
what is the correct order?

(A) Yes. http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order (see
no. 4)

(B) In order of importance, from least important to most important, e.g.

:link
:visited
:active
:hover
 
N

Nick Theodorakis

(A) Yes. http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order (see
no. 4)

(B) In order of importance, from least important to most important, e.g.

:link
:visited
:active
:hover

But in that case the "hover" properties will override those of
"active" when the link is clicked, which is probably not the effect
that is wanted. I would put the "active" pseudoclass last.

As to the first two, since "link" and "visited" are mutally exclusive,
I would presume that it wouldn't matter which of those two were first.

Nick
 
M

Mark Parnell

I'll use the order you provided above. I'm actually a little unclear on why
hover is more important than active, and why active is more important than
visited and why visited is more important than link? They all seem
important to me.

Visited and link are mutually exclusive, so it really doesn't matter
which way around you put them.

As for putting them before the others, if you define link last, they
will all (except visited) look like you have defined in the link rule,
even e.g. when you are hovering over the link.

Note that it is generally recommended to put hover before active, not
the way I had it above. :)
 
M

Mark Parnell

But in that case the "hover" properties will override those of
"active" when the link is clicked, which is probably not the effect
that is wanted. I would put the "active" pseudoclass last.

Teach me to send messages without checking what I am writing first.
As to the first two, since "link" and "visited" are mutally exclusive,
I would presume that it wouldn't matter which of those two were first.

That's correct, in theory. I haven't actually tested it on different
browsers, so no idea whether it actually works in practice. :)
 
B

Ben Amada

JustAnotherGuy & Mark,

Thanks for the clarification. I think I'm all set now with the order.

Regards,
Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top