WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > WEB DESIGN > CSS > css styling

Reply
  Thread Tools Display Modes
Old 24th May 12, 02:36 AM   #1
ricmetal
WLC Member
 
ricmetal's Avatar
 
Join Date: Feb 2011
Posts: 21
Default css styling

so, i've just learned that an element receives it's styling not in the order of the classes in it's class attribute, but in the order in which the classes are listed in the css file (or in-page stylesheet).

let me demonstrate:

.red { background-color:red; }
.black { background-color:black; }

<div class="black red">i am black</div>

is it just me, or does anybody else find this completely retarded?
am i missing something?
ricmetal is offline   Reply With Quote
Old 24th May 12, 08:25 AM   #2
chrishirst
Banned
 
Join Date: Jun 2006
Location: Blackp ool U.K.
Posts: 3,197
Default Re: css styling

Quote:
Originally Posted by ricmetal View Post
so, i've just learned that an element receives it's styling not in the order of the classes in it's class attribute, but in the order in which the classes are listed in the css file (or in-page stylesheet).

let me demonstrate:

.red { background-color:red; }
.black { background-color:black; }

<div class="black red">i am black</div>

is it just me, or does anybody else find this completely retarded?
am i missing something?
No and Yes in that order.

The bit you are missing is how HTML/CSS rendering engines work.

The first operation is to create the document STRUCTURE in the client user agent memory, that is torender the HTML into a memory model, the DOM.

Then the styling is applied as the rules are loaded/read so the last rule to be loaded (top down) takes priority. That is one of the reasons it is called cascading style sheets.

http://www.w3.org/TR/CSS21/cascade.html#cascade

For your case, when you are creating the cascade and you want "red" to take precedence over "black" add the !important modifier to the "red" ruleset.

While it may seem "anally retentive" to read the W3c documentation and specifications on HTML and CSS, it WILL mean that you have a better understanding of how things in HTML and CSS DIFFER from what you may expect when compared to a "real world" analogue, such as the W3c Box model
chrishirst is offline   Reply With Quote
Old 24th May 12, 04:41 PM   #3
ricmetal
WLC Member
 
ricmetal's Avatar
 
Join Date: Feb 2011
Posts: 21
Default Re: css styling

hi chris

i do read the specifications, just haven't gone through all of it nor do i read it from top to bottom.

thanks for the link

regards
ricmetal is offline   Reply With Quote
Old 24th May 12, 07:28 PM   #4
chrishirst
Banned
 
Join Date: Jun 2006
Location: Blackp ool U.K.
Posts: 3,197
Default Re: css styling

Quote:
just haven't gone through all of it nor do i read it from top to bottom.
You should

It can save you many problems when you understand the concepts, rather than trying to figure why it doesn't quite work as expected.

That's where Microsoft go wrong (IE6 & IE7) by using their own real world interpretation rather than applying the W3c concepts exactly as they are specified.
chrishirst is offline   Reply With Quote
Old 24th May 12, 09:10 PM   #5
ricmetal
WLC Member
 
ricmetal's Avatar
 
Join Date: Feb 2011
Posts: 21
Default Re: css styling

it's not that i don't understand the concepts, i figured the concept out (although reading the specifications would save me a whole lot of trouble).

my problem is with the lack of logic behid this concept regarding the class usage. css should aid html, not the other way round. if im typing in html and place a few classes in an element's attribute, it seems more logical that the html element uses the last class added.

either way, i've submitted a post to the w3.org board, see if i can change the way css works not likely, but i'll be the first (probably) to question the inner workings of css.

regards
ricmetal is offline   Reply With Quote
Old 25th May 12, 03:49 AM   #6
Phreaddee
WLC Lover
 
Phreaddee's Avatar
 
Join Date: Oct 2010
Location: Newcastle, NSW, Australia
Posts: 703
Default Re: css styling

yeah good luck getting them to change it from "cascading" to not.

its not a problem with the specification, but your implementation of it.
Phreaddee is offline   Reply With Quote
Old 25th May 12, 10:10 AM   #7
chrishirst
Banned
 
Join Date: Jun 2006
Location: Blackp ool U.K.
Posts: 3,197
Default Re: css styling

Quote:
my problem is with the lack of logic behid this concept regarding the class usage. css should aid html, not the other way round.
No, no that is not the case

CSS does not "aid" HTML nor is the intention of CSS to do so.
To use a "house" analogue, HTML is the STRUCTURE, the walls, floor and roof.
CSS is merely the paint and wallpaper used to colour or cover up the bare plaster and brickwork.
chrishirst is offline   Reply With Quote
Old 28th May 12, 10:41 PM   #8
ricmetal
WLC Member
 
ricmetal's Avatar
 
Join Date: Feb 2011
Posts: 21
Default Re: css styling

you proved me right, chris.

Quote:
Originally Posted by chrishirst View Post
HTML is the STRUCTURE, the walls, floor and roof.
CSS is merely the paint and wallpaper used to colour or cover up the bare plaster and brickwork.
CSS makes HTML look good just like paint does with a house. how is that not called aiding?

i know i should implement CSS like it works, but that's just my beef. it's counter-intuitive.


anyway, here's a CSS joke lol

HTML: no, no, i want white walls.
CSS: sorry, the latest paint cans we received were green, so we have to paint the walls green.



regards
ricmetal is offline   Reply With Quote
Old 29th May 12, 06:12 AM   #9
Phreaddee
WLC Lover
 
Phreaddee's Avatar
 
Join Date: Oct 2010
Location: Newcastle, NSW, Australia
Posts: 703
Default Re: css styling

HTML: tell the person who bought the green cans he's an idiot. we already had white.
CSS: I know, and I'd be happy to paint the walls white for you, but he seems to think you can have 2 different versions of the same selector and I'm going to be able to guess which one he actually want to use. I assume the latest one he added, what else can I do???
HTML: sounds logical to me.
Phreaddee is offline   Reply With Quote
Old 29th May 12, 07:09 AM   #10
ricmetal
WLC Member
 
ricmetal's Avatar
 
Join Date: Feb 2011
Posts: 21
Default Re: css styling

that's my point, CSS should not assume.

CSS: he bought two colors. as i don't know which one to use let's look at the blueprint, instead of being a douche and assuming that the last color i bought is the one to be used.

...

regards
ricmetal is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:50 PM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyright© 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.