css cascade - Different levels of CSS and the priority over each other -


i reading decent article here on topic: http://www.plus2net.com/html_tutorial/css-types.php came out highest ranked google search term css style sheets priorities. think site misinforms , incomplete! can confirm suspicions?

1) user defined style second lowest priority. in order override other styles it, need use !important move highest. 2) fails mention relative priorities of <link> versus @import , @import within <link>

a more precise ordering (1 wins on 2 etc) :

  1. user defined (browser prefs !important - [not google chrome!])
  2. inline style sheet (style attribute on html node)
  3. internal style sheet (<style> in <head>)
  4. external style sheet (@import)
  5. external style sheet (<link>)
  6. external style sheet (@import inside <link>)
  7. user defined - (browser prefs - [not google chrome!])
  8. browser default - (shipped browser)

michael bowers pro css & html design patterns source too. fails mention inline.

is there else missing?

ps: inferring !important missing 2-8. user defined appears twice. once important, second time without it. user defined in essence second lowest. !important can naturally applied @ level.

rather thinking of in terms of important , least important, think of cascade order. styles applied, last applied 1 one see. styles applied in following order:

  1. browser default
  2. external style sheet (link or @import)
  3. internal style sheet
  4. inline style

within 1 of first three, styles applied least specific specific (then top bottom if specific can't determined). tag-selected style applied before class-selected style, if disagree style should applied, class-selected 1 win. there no rule whether link or @import should applied first, mixed , least-specific-to-most-specific rule applies.

!important makes less specific style applied after more specific one, , external style sheet style applied after internal 1 or inline style. advise against using !important wherever possible though, can cause pretty confusing results.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -