473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Does style declarations order matter?

Hi,

Is it specified somewhere in the docs that pseudo styles
for links should be given in any specific order, and why?
In the code below, the link in the blue paragraph becomes red when the mouse passes over, but the A:hover spec is simply ignored if it is not the last one.

<html>
<head>
<title>Untitled</title>
<STYLE>
P.blue {color:blue}
P.blue A:link {color:green}
P.blue A:visited {color:green}
P.blue A:hover {color:red}
</STYLE>
</head>

<body>
<P>Paragraph with a <A HREF="#">link</A></P>
<P CLASS="blue">Blue Paragraph with a <A HREF="#">link</A></P>
</body>
</html>

Jan 27 '06 #1
2 1593
Els
Claude Schneegans wrote:
Hi,

Is it specified somewhere in the docs that pseudo styles
for links should be given in any specific order, and why?
In the code below, the link in the blue paragraph becomes red when the mouse passes over, but the A:hover spec is simply ignored if it is not the last one.


[snip code]

That's because the cascading of the styles.
The last one overrules the earlier ones.

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Now playing: Caravan - With An Ear To The Ground You Can Make Tt /
Martinian / Only Cox / Reprise
Jan 27 '06 #2
On Fri, 27 Jan 2006, Claude Schneegans wrote:
Is it specified somewhere in the docs that pseudo styles for links
should be given in any specific order,
Not directly, but it's usually explained in tutorials.
and why?
Application of logic to the rules set out in the specifications :-}
In the code below, the link in the blue paragraph becomes red when
the mouse passes over, but the A:hover spec is simply ignored if it
is not the last one.


For selectors from the same source and of equal specificity, the last
takes priority. Something like that, anyway - don't ever believe what
Usenet tells you - treat it as potentially misleading clues, verify it
at the source. In this case the CSS spec cascading rules.

What the usual tutorials omit to mention is that selectors like
a:hover *will* select <a name="foo">bar</a>, which probably isn't what
you'd intend.

One hunch is that those who wrote the tutorials had only used MSIE,
which doesn't implement :hover to specification. Or maybe they
thought that use of <a name=...> had already been phased out, and
nobody had any legacy documents to which they were applying CSS. OK,
maybe you're in that lucky situation; but some of us have been doing
HTML since 1994-ish, and doing CSS since its early drafts (thanks to
the Arena browser), and have all kinds of legacy stuff to take into
account.

I do think the tutorials might mention a:link:hover (and optionally
a:visited:hover) as being more robust ways of selecting links without
accidentally affecting also anchors. You might want to style :active
too, and possibly even :focus, by the way.

There's a crazy mnemonic, "Las Vegas Forest Has Animals", to remember
an appropriate sequence for them. But that's not set in stone: it
rather depends on what you want to happen in the various scenarios.

Jan 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michael Tobis | last post by:
Summary of my understanding of a recent interesting thread: General usage has "declaration" meaning "statement which does not generate executable bytecode but merely affects the compiler". My...
3
by: macgyver | last post by:
This is a strange question, and I think the answer is NO, but I am asking anyway. I am a member of a website which allows us to alter our member profiles. Using css in the middle of the profile...
7
by: YGeek | last post by:
Is there any difference between declaring a variable at the top of a method versus in the code of the method? Is there a performance impact for either choice? What about if the method will return...
63
by: Papadopoulos Giannis | last post by:
Which do you think is best? 1. a) type* p; b) type *p; 2. a) return (var); b) return(var); c) return var;
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
43
by: Sensei | last post by:
Hi! I'm thinking about a good programming style, pros and cons of some topics. Of course, this has nothing to do with indentation... Students are now java-dependent (too bad) and I need some...
1
by: smith | last post by:
I was recently set to release an app that used very common single instance code and hit the oddest issue. After many hours of full build tests I believe that it is duplicatable. Environment: ...
12
by: fox | last post by:
How do I (portably) make a forward reference to a static (I mean file-scope) variable? I've been using "extern" for years, for example: extern int x; int foo(void) { return x++; }
2
by: Jim Langston | last post by:
In my function/method paramater list I try to keep constant correctness. I.E. I would use: int Foo( const char* a, int b ) instead of int Foo( char* a, int b ) My question reguards int b. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.