6 replies [Last post]
jimvj
Offline
newbie
California
Last seen: 15 years 42 weeks ago
California
Timezone: GMT+8
Joined: 2005-01-01
Posts: 5
Points: 0

Two questions (and if they've been asked/answered before please accept my apology & direct me to the sites):

1. Given this in a css file: .r {text-align: right}

The syntax to use this is, e.g., <p class="r">.

Why not allow the simpler/more compact syntax: <p.r> ?
And similarly, <p#another_css_definition>.

2. Is "multiple-inheritance" allowed (or to be allowed in future versions?
I.e., if the css file also has .f8 {font-size:"8pt"}

Could one use <p class="r" class="f8"> ?

Thanks

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 days 18 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

CSS syntax questions

Hi jimvj,

Quote:
Why not allow the simpler/more compact syntax: <p.r> ?
And similarly, <p#another_css_definition>.

Actually that looks to be more confusing to me, its much simpler to clearly define the class so that it is not confused as part of the tag name.
Also it is not part of the specs as far as I know and wouldn't be supported by any browsers.

Quote:
2. Is "multiple-inheritance" allowed (or to be allowed in future versions?
I.e., if the css file also has .f8 {font-size:"8pt"}

Could one use <p class="r" class="f8"> ?

You can use multiple classes like <p class="r f8">

Hope that helps

jimvj
Offline
newbie
California
Last seen: 15 years 42 weeks ago
California
Timezone: GMT+8
Joined: 2005-01-01
Posts: 5
Points: 0

CSS syntax questions

Thanks for the reply, Tony.

Nice to know about the multiple class use.

The syntax <p.r> is what is used in the css file.
e.g.
p.r { some stuff }

If it is good enough for a .css file, why not for an html file?

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 days 18 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

CSS syntax questions

Hi jimvj,
HTML was around before CSS.
If they were developed at the same time and the developers thought it was a good idea, it would have been possible to implement.
To make changes to the html specks is not a simple thing, it takes time for browsers to catch up and in the mean time all the older browsers would not have a clue how to handle the new syntax.

DCElliott
DCElliott's picture
Offline
Leader
Halifax, Canada
Last seen: 3 years 24 weeks ago
Halifax, Canada
Timezone: GMT-3
Joined: 2004-03-22
Posts: 828
Points: 0

CSS syntax questions

One reason not to use p.r as a class name is that in its .r form, it is a universal class for right aligning text while p.r will only work in paragraphs. There may be times when you want the increased specificity of p.r or the much higher specificity of #r (although you could only use it once) . The differences aren't important in most simple stylesheets but if you have a complex site with multiple stylesheets, specificity becomes an issue.

Tony didn't mention it but <p class="r" class="f8"> would only apply the f8 style (a second class attribute overwrites the first) while <p class="r f8"> will apply both classes.

DE

David Elliott

Before you ask
LearnXHTML|CSS
ValidateHTML|CSS

jimvj
Offline
newbie
California
Last seen: 15 years 42 weeks ago
California
Timezone: GMT+8
Joined: 2005-01-01
Posts: 5
Points: 0

CSS syntax questions

Thanks for all the replies. At the risk of beating a dead horse,
I was suggesting that <p.r> would be semantically equivalent
to <p class="r">, regardless of whether .r was defined as a
universal class (i.e. as .r {...} ), or as specific to (say) p only
(i.e. as p.r {...}). In both cases we can use <p class=r ...>,
and <p.r ...> would be semantically identical.

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 38 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

CSS syntax questions

It would be. But as Tony said, it'll never happen, especially with HTML coming closer to XML specs, and backward-compatiability, etc etc.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.