View Full Version : Why Can't Class Equal Red?
morestar
12-30-2010, 03:19 PM
I was just thinking: wouldn't it be neat and more sophisticated in this here year of 2010 for browsers to be able to interpret tag class names like the following:
class="red"
as their colors without me having to set the class in the CSS file?
Evolution of browsers? - maybe one day - that is unless Opera already does it. ;p
KatyS
12-30-2010, 03:48 PM
maybe, but which bit, background or text colour?
williamc
12-30-2010, 03:49 PM
Ummm... style="color:red" or style="background-color:red" work fine.... the way you suggest would be a redefinition of coding standards, which is not likely to happen.
morestar
12-30-2010, 03:53 PM
Yes yes I know William - of course lol you must think im nuts.
I mean once I write this bit: class="red" in the code, I don't have to set the style color in the CSS. Basically wishing the browsers would pic up the style on their own and render the color of the element in quest as stated in the class name.
Bah, shouldn't be done on second thought, can't be done, if that type of changed happened, suddenly being released by browsers webpages all over would be screwed up.
williamc
12-30-2010, 03:55 PM
Bah, shouldn't be done on second thought, can't be done, if that type of changed happened, suddenly being released by browsers webpages all over would be screwed up.
As I said above, it would redefine coding standards.
morestar
12-30-2010, 04:01 PM
I wonder why this wasn't brought up in the beginning - or if it was as there's no logical reason 'red' should mean any other thing from a styling perspective.
williamc
12-30-2010, 04:04 PM
Umm because it would require browsers to first look at a list of predefined names, then look at the styles to see if there was one named 'red' and then finally use the color red. Why on earth would they do something as silly as all that when the style attribute does what you are asking for already without any unneeded lookups causing a larger resource footprint? A class in ANY coding language has always been a seperate entity read in for specific tasks. Why would the makers of CSS deviate from that standard?
HTMLBasicTutor
12-30-2010, 04:23 PM
Interesting idea. My question would be: How do you define the red? It could be stop sign red, an orange red, a burgundy red, ...
williamc
12-30-2010, 04:25 PM
an orange read
Why would anyone want to read an orange? :)
crankydave
12-30-2010, 04:29 PM
Why would I want my browser to take 2 days to render a page?
weegillis
12-30-2010, 04:30 PM
The further consideration is semantics as determined in the document markup and structure. Apart from the browsers needing to include lookup references, the determination of foreground and/or background (as noted above) would also bring about a whole plethora of inequities, cross browser. One can easily envisage the kerfuffle, and this was very likely talked about in the early days of the working groups.
The current trend toward a more semantic web, and the advent of a 'smarter and better defined' language construct, HTML5 and CSS3, both lend themselves to context. That an object is red, is better defined by its context, not its class. Put in the context of a warning, notice or reminder, red might easily be the color chosen to signify these elements.
williamc
12-30-2010, 04:32 PM
Why would I want my browser to take 2 days to render a page?
So you could just use class="red" of course.... :p
SteveGerencser
12-30-2010, 04:38 PM
I really hadn't intended to post in this thread, but a thought struck as contradictory in your thought processes Morestar.. On one hand you want easier code in css by balling up things like class="red" and on the other hand you want to add to the amount of low level code by stuffing things like RDFa and microtags everywhere.. I just find the contradiction in thought processes interesting.. Fine low level control vs broad brush strokes which level everything generic and 'same'..
HTMLBasicTutor
12-30-2010, 04:53 PM
Why would anyone want to read an orange? :)
Fixed typo
williamc
12-30-2010, 05:07 PM
Fixed typo Gah, I was just interjecting some comedy, please do not think I am some spelling nazi :p
morestar
12-30-2010, 08:46 PM
I really hadn't intended to post in this thread, but a thought struck as contradictory in your thought processes Morestar.. On one hand you want easier code in css by balling up things like class="red" and on the other hand you want to add to the amount of low level code by stuffing things like RDFa and microtags everywhere.. I just find the contradiction in thought processes interesting.. Fine low level control vs broad brush strokes which level everything generic and 'same'..
Ya, that interpreted contradiction in this case would be purely out of context.
The nature of THIS post was sparked after a small "huff" where I knew any moment I would have to jump into my CSS and write .red{color:#ff0000;}.
The last time I programmed my own browser was in 2000 in college - it was in VB and definitely couldn't compete with Opera - even if I tried.
I'm not Mr. Concerned about stuffing or reducing code for any purposes. I trust most browsers, search engines and users can see what I want them to see.
Although the value "_blank" in the attribute 'target' doesn't need an external file to define it's behaviour I obviously couldn't expect the value of the attribute class to function that way - it would be nice but as a few have pointed out, it would muck up the whole system.
Capisce?
williamc
12-30-2010, 09:13 PM
class="" does not actually need an external file either as the styles class could easily be on the same page. Just as target= can not call an external file at all, as that was not how that particular attribute was designed. The target= attribute is much like the style= attribute, whereas the class= attribute functions much more like an include than a descriptor.
Optic
12-30-2010, 09:19 PM
Syntactically Awesome Stylesheets (SASS) look pretty interesting, though I haven't played with it yet.
http://sass-lang.com/
This is pretty much dynamically generated CSS.
morestar
12-30-2010, 09:19 PM
class="" does not actually need an external file either as the styles class could easily be on the same page. Just as target= can not call an external file at all, as that was not how that particular attribute was designed. The target= attribute is much like the style= attribute, whereas the class= attribute functions much more like an include than a descriptor.
That's what I said, of course it (target="_blank") wasn't built to work the same way - and that was my point when I conceded the notion that it would have been a good idea.
And, again, the post was spawned from the context of my thoughts :) when I was writing class="red" and wishing I didn't have to ALT TAB back into my CSS and type .red{color:#ff000;}.
Capisce??
morestar
12-30-2010, 09:23 PM
Syntactically Awesome Stylesheets (SASS) look pretty interesting, though I haven't played with it yet.
http://sass-lang.com/
This is pretty much dynamically generated CSS.
I saw that once, recently, in a style sheet and it looks like it might be the future of CSS - it doesn't look too complicated either.
weegillis
12-30-2010, 10:02 PM
When reading a style sheet, I find much more meaning in something like this:
.notice, .warning, .reminder { color: red; background: transparent;}
than I do with, .red {color: red;}.
First, I know what elements are expected to be red in foreground, and second, though minor, I also know what background to expect, even if as above, it is the existing one.
As a complete aside, I've often stressed the importance of color pairs, FG and BG never being broken up. This mostly helps to validate a CSS file, but it's original importance is not lost, that of describing more fully the color properties for a given element.
Why Can't Class Equal Red?
Because a CSS class is not a template for an object (user defined data type) that you may think of.
Don't confuse the CSS class concept with the class concept in a true object oriented language: http://www.webproworld.com/webmaster-forum/threads/44904-A-soft-introduction-to-object-oriented-programming.
Personally I don't see (X)HTML and CSS as programming languages.