In article <
9q3do7hdqgsmh8bhn...@4ax.com>,
steve....@gmail.com says...
>
> I have defined a class, "sunset" as:
>
> .sunset {color:red}
>
> Can I add things like:
>
> a:link {color:#611}
>
> ... into the "sunset" class, such that all links inside a <SPAN
> CLASS=sunset> inherit the #611 colour?
Yes (but)...
I had to think about this, as it's not the way I'd usually do things
(but then, I'm no guru here). Here's some code:
####################
<style type="text/css">
<!--
p {
color: blue;
font-style:italic;
}
.sunset {
color: red;
font-style: normal;
}
a:link {
color: green;
font-weight: bold;
}
-->
</style>
...
<p>This is my <span class="sunset">sunset text</span> in an otherwise
unremarkable paragraph.</p>
<p>This is my <span class="sunset">sunset text with a <a href="#"
title="dummy link">link</a> now </span>in an otherwise unremarkable
paragraph.</p>
##################
The normal rule of "specificity" applies, meaning broadly that the rule
with the most precise match will take priority over a more general
match. In this case the link appears green rather than red, as the
a:link selector is more specific than the SPAN one (and the SPAN itself
is more specific than the rules which might apply the the containing
paragraph).
However, there's more to specificity than just how deeply the nesting
goes. You might like to look at one or more of these articles:
http://www.htmldog.com/guides/cssadvanced/specificity/
http://css-tricks.com/specifics-on-css-specificity/
http://reference.sitepoint.com/css/specificity
So you probably want to work on your selectors a bit, or you'll find
that some change you make later down the road has unexpected side
effects! Your code (ok, obviously example code) refers to any link,
whereas you'll probably want to distinguish links in a navigation
structure from any old inline link provided for visitors to follow up a
reference if they want to. I usually put "navigation" links within LI
items within a UL. I put a class or ID on the UL, and then refer to the
links in CSS like this:
UL.nav li a:link,
UL.nav li a:visited { color: nice;}
UL.nav li a:hover,
UL.nav li a:active { color: nicer;}
Note that your browser will have a "default stylesheet" (that's why even
unstyled H1 elements look more prominent than unstyled H2 elements) and
this default stylesheet will normally contain rules for the four
different attributes a link can take, so if you don't provide your own,
you may find the link looks different after you've visited it and
returned back!
For ordinary inline links you could either put in a set of default link
styles:
a:link,
a:visited { some stuff}
a:hover,
a:active { other stuff}
... and then make sure that any links which ought to look different have
more specific CSS selectors (like the links in my UL.nav above), or you
could give an explicit class to your ordinary links, like this:
a.vanilla:link,
a.vanilla:visited { some stuff}
a.vanilla:hover,
a.vanilla:active { other stuff}
or maybe put in a rule that would pick out links which happened to be in
any paragraph:
p a:link,
p a:visited {some stuff}
p a:hover,
p a:active { other stuff}
Returning to the specifics of your question, consider this CSS:
.sunset a:link {color: #611;}
An interesting question, as it's made me think hard about some
fundamental issues. Hope my answer is too.
CSS is easy to learn. In fact, it's no harder to learn than Chinese -
and one in four of the world's children are pretty fluent in Chinese by
the time they are five years old.
--
Phil, London