Scripsit Puzzled:
Quote:
I'm obviously reading the docs wrong, or doing something wrong, |
Well, yes. It's almost evident from the Subject line, since more than
99% of people's questions formulated in terms of inheritance are based
on completely wrong assumptions (and mostly have nothing to do with
inheritance).
Quote:
so I hope someone can put me right. |
OK, but it won't be easy.
Quote:
What I want is to be able to define a style |
Technically, style sheets have no style. That is, "a style" is not a CSS
term. CSS has properties, values, declaration, rules, and styles sheets
(to proceed bottom up in the hierarchy of concepts). Informally, we
might call a collection of declarations "a style", and this is probably
what you mean.
Quote:
and apply it to, say,
a <td>, define another style and have it apply to embedded <a>s
within that <td> regardless of any intermediate unstyled nesting. |
OK, that should be easy.
Quote:
E.g., if the <a> is within an unstyled <p> (i.e. nothing being
inherited from the <p/>), it should still use the style defined
for <a> inside <td>. |
Here's the first mistake: "nothing being inherited from the <p/>". An
element can surely inherit from an "unstyled" parent, since such a
parent (as any element) has all the properties there are in CSS.
Quote:
I shouldn't have to define the case of the
a> within a <p> within the <td>. |
You don't. When you assign a value to a property of an element, then
that element does not inherit a value for that property, no matter where
the element is nested.
Quote:
As I read the docs, this should work:
*[class="tdclassname"] A {definition} |
Here "definition" should be replaced by "declaration(s)".
It should work, but the following is much safer, since it works on IE
prior to IE 7, too:
..tdclassname A {declaration(s)}
Quote:
so both <a> tags here:
td class="tdclassname"
a ...
p/
a ...
/td
...should have the same style. |
Uh... tags have no style. Elements have style. And you probably mean <a
....>...</a>, since an <a> element always needs an end tag. Moreover,
<p/> is all wrong: such notation is strongly discouraged (though
formally permitted both in classic HTML and in XHTML, with completely
different meanings), and in XHTML it is formally equivalent to <p></p>,
i.e. an empty paragraph, which should (by HTML specs) not be used and
should (by HTML specs) be ignored by browsers, though in practice they
tend tp present it as some amount of empty space.
There's little hope in successful use of CSS before you have the markup
at least roughly right.
Whether the two <a> elements have "the same style", which probably means
same values for properties, really depends on other style sheets,
possibly even browser default style sheets. But what you set in
..tdclassname A {declaration(s)}
applies equally well to the <a> element that resides as nested inside a
<p> element.
However, for example, if you have
body { font-family: Arial; }
p { font-family: Calibri; }
(just to take a definite, though foolish, example) and no other
font-family settings anywhere, then the <a> element nested inside a <p>
element will inherit font-family from its parent, i.e. appear in
Calibri, unlike the other <a> element, which is in Arial. You can easily
prevent this by explicitly setting, for example,
a { font-family: Arial; }
which makes all <a> elements appear in Arial. But there is no way to
prevent an element from inheriting a property from its parent except by
setting a value for that property for that element.
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/