Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Rules - Style Sheet Precedence Question

Started 1 month, 2 weeks ago by erj145
So the basic rules are: 1) Author style sheets 2) User style sheets 3) Default browser sheets Now when you get into Author style sheets... You have: inline styles, header style information (<style type="text/css"> </style>), external style sheets and imported style sheets. I created a little example for myself to figure out the precedence. So that if all of these...
Site: Dev Shed Forums - Open Source web development  Dev Shed Forums - Open Source web development - site profile
Forum: CSS Help  CSS Help - forum profile
Total authors: 3 authors
Total thread posts: 14 posts
Thread activity: no new posts during last week
Domain info for: devshed.com

Other posts in this thread:

Akh replied 1 month, 2 weeks ago
The rule that is declared last wins, if they have equal weight. In your last example the style from the link element is declared later than the style in the style-element so it wins. Code: <html> <head> <style type="text/css"> @import url(import.css); p { color: blue; } </style> <link href="link.css" rel="stylesheet" type="text/css" /> </head> ...

DonR replied 1 month, 2 weeks ago
I think this should be stickied if it isn't already. Really good info for those starting to learn CSS.

erj145 replied 1 month, 2 weeks ago
Thanks for the info. It seems that the order of precedence is: 1) Inline styles 2) Header style information 3) External Style Sheets External style sheets are composed of: A) Linked style sheets. B) Imported style sheets. The exception is that linked style sheets are of equal weight compared to header style information, whereas imported style sheets are ...

Akh replied 1 month, 2 weeks ago
Not quite right. As I said the style that is declared last wins if they have the same specificity value. You could have Code: <style type="text/css"> p { color: blue; } </style> <style type="text/css"> @import url(import.css); </style> Where the imported css file would overrule the embedded style.

Akh replied 1 month, 2 weeks ago

erj145 replied 1 month, 2 weeks ago
Ok, I think I got it now. So the order of precedence is established by specificity. 1) Inline Styles 2) Header Style Information AND External Style Sheets. Point 2: Whichever has the greatest specificity wins.

erj145 replied 1 month, 2 weeks ago

erj145 replied 1 month, 2 weeks ago
If that is the case... Why wouldn't the style within import.css win in this case: Code: <style type="text/css"> P { color: red; } @import url(import.css); </style> Both declarations have the exact same style with the exception of color value. Based on specificity, they would both be equal. Yet the header style information wins over the ...

erj145 replied 1 month, 2 weeks ago

Akh replied 1 month, 2 weeks ago
No, browsers should ignore that @import rule. @import rules must precede all other rules (except the @charset rule, if present). http://www.w3.org/TR/CSS21/cascade.html#at-import CSS 2.1 user agents must ignore any '@import' rule that occurs inside a block or after any non-ignored statement other than an @charset or an @import rule. http://www.w3.org/TR/CSS21/...

 

Top contributing authors

Name
Posts
erj145
8
user's latest post:
Rules - Style Sheet Precedence...
Published (2009-11-14 12:51:00)
Thank you.
Akh
5
user's latest post:
Rules - Style Sheet Precedence...
Published (2009-11-14 12:39:00)
No, browsers should ignore that @import rule. @import rules must precede all other rules (except the @charset rule, if present). http://www.w3.org/TR/CSS21/cascade.html#at-import CSS 2.1 user agents must ignore any '@import' rule that occurs inside a block or after any non-ignored statement other than an @charset or an @import rule. http://www.w3.org/TR/CSS21/syndata.html#at-rules
DonR
1
user's latest post:
Rules - Style Sheet Precedence...
Published (2009-11-13 17:07:00)
I think this should be stickied if it isn't already. Really good info for those starting to learn CSS.

Related threads on "Dev Shed Forums - Open Source web development":

Related threads on other sites:

Thread profile page for "Rules - Style Sheet Precedence Question" on http://www.devshed.com. This report page is a snippet summary view from a single thread "Rules - Style Sheet Precedence Question", located on the Message Board at http://www.devshed.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity