[Pmwiki-users] PmWiki skinning

Patrick R. Michaud pmichaud
Tue Nov 9 08:04:28 CST 2004


On Tue, Nov 09, 2004 at 12:54:34AM +0000, Val Sharp wrote:
> Patrick R. Michaud, on 08.11.04 19:08, wrote:
> > The precedent for rules in <style> vs. <link> depends on the order
> >in which they are declared--the one declared later gets higher 
> >priority ...
> 
> The world is not as I thought it was!  :-\
> 
> I can find nothing in HTML4.01, CSS1 / 2 / 2.1 / 3 to contradict what 
> you say, though every website I see on how to write stylesheets says 
> that embedded stylesheets take precedence over external 
> stylesheets[1]. It never occurred to me to question this widely held 
> belief, but I'm obviously wrong here.

I think it's confusion over the meaning of "embedded style sheet".
Surprisingly, the word "embedded" appears only once in the CSS 1 spec 
(simply to say that it's convenient to put such style sheets inside HTML 
comments), and "embedded" doesn't appear in the CSS 2 spec at all.  

The proper term is "imported style sheets", and this term refers only 
to rules in stylesheets obtained via the CSS '@import' rule--not those
coming from <link> (which are actually considered as separate sheets).  

Even in the context of using '@import', rule ordering is only 
significant within a single sheet--i.e., the rules that appear within 
the <style> element that contains the '@import'--and not the
entire "document".  This is actually enforced by the CSS requirement that
'@import' statements must occur before any other rules in the sheet [1] [2],
thus rules in imported style sheets are considered to be before any
rules in the sheet itself.  However, each <style> or <link> element
constitutes a separate "sheet", and for these separate sheets
the order in which they appear within the document is the (only)
controlling factor.

As a demonstration (I agree that browser behavior doesn't constitute 
a real "proof"), see http://www.pmichaud.com/sandbox/css-test-3.html .

> Just goes to show that many people believing something still doesn't 
> make it true.

Indeed.  I think the misconceptions likely began in the early days of
CSS and has simply been propagated from one author to the next.  There's
a tendency to want to over-emphasize the "cascading" aspect of CSS, and
I think this leads to imagining complexity where it doesn't exist.  Plus,
it's all to easy to misread the CSS spec that says

    Rules in imported style sheets are considered to be before 
    any rules in the style sheet itself. [3]

as if it had said
    
    Rules in imported style sheets are considered to be before 
    any rules in the [document].

Personally, I find it's easier to ignore the source (internal vs. external) 
of rules entirely, and just use the order in which they occur within the
document.  That is, if two rules have equal specificity according to the 
other CSS selection criteria, then the rule that is defined latest in the 
document is used regardless of whether it came from <link>, <style>, or
@import.  I haven't found anything that contradicts this way of looking
at the document, and the HTML 4 spec supports it:

    To define a cascade, authors specify a sequence of LINK and/or 
    STYLE elements. The style information is cascaded in the order 
    the elements appear in the HEAD. [4]

Pm


1.  "In CSS1, all '@import' statements must occur at the start of a 
    style sheet, before any declarations. This makes it easy to see 
    that rules in the style sheet itself override rules in the 
    imported style sheets."  http://www.w3.org/TR/CSS1#the-cascade

2.  Any @import rules must precede all rule sets in a style sheet. 
    http://www.w3.org/TR/CSS21/cascade.html#at-import

3.  http://www.w3.org/TR/CSS1#cascading-order

4.  http://www.w3.org/TR/html4/present/styles.html#h-14.4.2




More information about the pmwiki-users mailing list