Go Back   SitePoint Forums > Forum Index > Design Your Site > Web Page Design > CSS
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Feb 27, 2008, 05:41   #1
Php_penguin
SitePoint Addict
 
Php_penguin's Avatar
 
Join Date: Aug 2004
Location: Colwyn Bay, Wales, UK
Posts: 289
Notice: This is a discussion thread for comments about the SitePoint article, Get Specific with Your CSS Styles.
__________

I really wish that things just happened in the order they appeared in the stylesheet, ignoring specificity..
Php_penguin is offline   Reply With Quote
Old Feb 27, 2008, 05:58   #2
Stevie D
SitePoint Community Guest
 
Posts: n/a
I think you've got a comma in the wrong place. "If one declaration is from a style attribute, rather than a rule with a selector (an inline style)," should be "If one declaration is from a style attribute, rather than a rule with a selector, (an inline style)".

The way you've written it makes it look as though a rule with a selector is called an inline style, not the other way round...
  Reply With Quote
Old Feb 27, 2008, 06:32   #3
Carlton Dickson
SitePoint Community Guest
 
Posts: n/a
Great article Paul, feel like I fully understand this concept now.

For anyone wanting some more info on CSS specificty you should also read although it misses the important part of inline styles

http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html

@Php_penguin Why do you wish that? If you have to include multiple CSS files it would be horrible having to worry about if your styles were being overwritten.
  Reply With Quote
Old Feb 27, 2008, 06:55   #4
Stevie D
SitePoint Community Guest
 
Posts: n/a
1. Why have you taken tabular data and saved it as an inaccessible image file, instead of a properly marked up table?

2. When styles of equal specificity are defined in different places (eg multiple stylesheets and css called via @import), is it still the last rule in the last referenced stylesheet that takes precedence?
  Reply With Quote
Old Feb 27, 2008, 07:29   #5
Paul O'B
CSS Advisor
 
Paul O'B's Avatar
 
Join Date: Jan 2003
Location: Hampshire UK
Posts: 26,608
Quote:
2. When styles of equal specificity are defined in different places (eg multiple stylesheets and css called via @import), is it still the last rule in the last referenced stylesheet that takes precedence?
Yes

It makes no difference where styles come from as they are inserted into the cascade order at the point they were called from (remembering that the @import rules in a style sheet must precede all rule sets anyway.).

As all styles are called into the page (by link or import) then they occupy the position in the order that they were called from.

Quote:
1. Why have you taken tabular data and saved it as an inaccessible image file, instead of a properly marked up table?
You'll have to ask the editor
Paul O'B is online now   Reply With Quote
Old Feb 27, 2008, 08:14   #6
timwright
SitePoint Member
 
timwright's Avatar
 
Join Date: Feb 2008
Location: Santa Monica, CA
Posts: 9
Keep in mind that @import rules require extra HTTP requests to the server. So if you're having web site performance issues, that can be a source.

That was kind of off-topic.

Good article, I'm a big fan of putting an ID and class on the body element. It keeps HTML really clean, and you can also style the html and body elements for page width, rather than using a "container" or "wrap" div... big fan.
timwright is offline   Reply With Quote
Old Feb 27, 2008, 11:17   #7
Stevie D
SitePoint Addict
 
Join Date: Mar 2006
Posts: 213
Quote:
Originally Posted by Paul O'B View Post
It makes no difference where styles come from as they are inserted into the cascade order at the point they were called from (remembering that the @import rules in a style sheet must precede all rule sets anyway.).

As all styles are called into the page (by link or import) then they occupy the position in the order that they were called from.
What I was thinking is that you could have the situation where you had two linked stylesheets, and each of them had @import rules at the top.
So the order of preference would be that any declarations in the second sheet would be the most important, followed by any in the sheet @imported by the second stylesheet, followed by declarations in the first stylesheet, and finally anything in the sheet @imported by the first stylesheet.
Stevie D is offline   Reply With Quote
Old Feb 27, 2008, 12:00   #8
ParkinT
SitePoint Evangelist
 
ParkinT's Avatar
 
Join Date: May 2006
Location: Orlando
Posts: 588
Great article! I did not realize the rules had changed (slightly) with CSS2.
One point that (still) causes me confusion [when constructing markup] is the 'default' values.
In other words, remembering what is 'margin-left' and must I override it for the desired effect.
ParkinT is offline   Reply With Quote
Old Feb 27, 2008, 14:15   #9
Paul O'B
CSS Advisor
 
Paul O'B's Avatar
 
Join Date: Jan 2003
Location: Hampshire UK
Posts: 26,608
Quote:
Originally Posted by Stevie
What I was thinking is that you could have the situation where you had two linked stylesheets, and each of them had @import rules at the top.
So the order of preference would be that any declarations in the second sheet would be the most important, followed by any in the sheet @imported by the second stylesheet, followed by declarations in the first stylesheet, and finally anything in the sheet @imported by the first stylesheet.
If I'm not misunderstanding what you just said then that sounds correct

The styles get imported into the page at the position they occupy in the stylesheet so the @imported files must be at the top of the stylesheet anyway and therefore the rest of the rules (if any) will follow after.

It might be clearer for argument sake to imagine that if you see a link/import to a stylesheet then just imagine those styles linked to are already present in the document at that exact position where the link is. The styles are then resolved by the normal cascade rules just as if they had always been in that stylesheet.

Therefore the fact that the styles are are brought in from elsewhere is mainly irrelevant (unless we are talking user stylesheets with !important of course).

If you had a construct like this:

Code:
<link href="test1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
@import url("test2.css");
@import url("test3.css");
p{color:red}
</style>
If each of the above styles contained only one rule to define the the p element then you can just imagine that the result is as follows had you simply embedded all the styles in the page:
Code:
<style type="text/css">
p{color:blue}/* from test1.css*/
p{color:green}/* from test2.css*/
p{color:yellow}/* from test3.css*/
p{color:red}/* last in sequence */
</style>
Hope that was what you meant
Paul O'B is online now   Reply With Quote
Old Feb 27, 2008, 16:21   #10
mattymcg
Team SitePoint
 
mattymcg's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 566
Quote:
Originally Posted by Stevie D View Post
1. Why have you taken tabular data and saved it as an inaccessible image file, instead of a properly marked up table?
Believe me, there are many things about our custom article CMS that annoy me, but the one thing that irritates me the most is its inability to handle tables. I feel dirty every time I do it. I know, I know. It is on the cards to completely revamp it, with proper unicode entity support and all sorts of other magical goodness. But until that's in place, we're stuck with it.
mattymcg is offline   Reply With Quote
Old Feb 27, 2008, 19:13   #11
Tyssen
SitePoint Wizard
 
Tyssen's Avatar
 
Join Date: Oct 2005
Location: Brisbane, QLD
Posts: 4,008
Quote:
Originally Posted by mattymcg View Post
It is on the cards to completely revamp it, with proper unicode entity support and all sorts of other magical goodness.
Something else that would be good would be reworking comments on articles so that they display the same as they do in the forum threads, ie, all comments showing, in correct order and with quoted passages in place.
Tyssen is offline   Reply With Quote
Old Feb 28, 2008, 23:32   #12
bohimt
SitePoint Member
 
bohimt's Avatar
 
Join Date: Feb 2008
Location: Atlanta, Georgia
Posts: 0
Who cares about this. Why don't people just make sure their styles don't conflict, and then the problem wouldn't exist?
bohimt is offline   Reply With Quote
Old Feb 29, 2008, 00:13   #13
mattymcg
Team SitePoint
 
mattymcg's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 566
Quote:
Originally Posted by bohimt View Post
Who cares about this. Why don't people just make sure their styles don't conflict, and then the problem wouldn't exist?
bohimt you've obviously never worked on a site that's very complex. Or perhaps you just asign an ID to everything and have a style sheet that's a mile long and full of redundant rules, just so that nothing conflicts, ever. Doesn't sound very workable to me.

Quote:
Originally Posted by Tyssen
Something else that would be good would be reworking comments on articles so that they display the same as they do in the forum threads, ie, all comments showing, in correct order and with quoted passages in place.
Couldn't agree more Tyssen. We're very aware of it, it's just one thing on a long list.
mattymcg is offline   Reply With Quote
Old Feb 29, 2008, 06:10   #14
Stevie D
SitePoint Addict
 
Join Date: Mar 2006
Posts: 213
Quote:
Originally Posted by bohimt View Post
Who cares about this. Why don't people just make sure their styles don't conflict, and then the problem wouldn't exist?
Because that either gives you a very limited repartee, or means that you have to define absolutely everything individually, which is a ridiculous amount of work.

A good example is highlighting an item in the navigation bar. If your styles are:
ul#nav li {general styles} and li#current {specific styles}, the general styles have greater specificity, so will always override the li#current. But if you have ul.nav li {general styles} and li#current {specific styles}, li#current will win out.

By understanding the specificity of different combinators and rules, you can generate far more complicated and powerful stylesheets using far less code - which saves time, saves bandwidth, and makes them a lot easier to read, edit and debug.
Stevie D is offline   Reply With Quote
Old Mar 3, 2008, 06:25   #15
NetNerd85
SitePoint Zealot
 
NetNerd85's Avatar
 
Join Date: Aug 2005
Location: Australia
Posts: 136
At first glance I thought this would be another pointless article but no it really taught me something new. You are completely right in saying it is poorly documented, look at the W3C standards. Good article mate!
NetNerd85 is offline   Reply With Quote
Old Mar 8, 2008, 05:00   #16
stefan burt
SitePoint Community Guest
 
Posts: n/a
Thank you for the article,
I thought I understood specificity to a fine level but this showed me I had a few cracks in my knowledge, it's a simple yet complex area of css and I'm glad I took the time in reading it.
  Reply With Quote
Old Mar 23, 2008, 04:01   #17
Ralph
SitePoint Community Guest
 
Posts: n/a
Thank you for this great article to think about to get a structure for css.

@stefan: Yes, this article is complex to read in two doors ;)

Ralph
  Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
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
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 15:56.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved