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) :
- user defined (browser prefs !important - [not google chrome!])
- inline style sheet (style attribute on html node)
- internal style sheet (<style> in <head>)
- external style sheet (@import)
- external style sheet (<link>)
- external style sheet (@import inside <link>)
- user defined - (browser prefs - [not google chrome!])
- 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:
- browser default
- external style sheet (
link
or@import
) - internal style sheet
- 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
Post a Comment