Forum Moderators: not2easy

Message Too Old, No Replies

CSS priority

         

tntpower

5:55 pm on Mar 10, 2010 (gmt 0)

10+ Year Member



I have two CSS files and I want one has priority. In other words, all CLASS/ID occurrences that are available in both CSS files should give priority to the one I specify.

Is there an easy way to do that?


Thanks,

Fotiman

6:15 pm on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Assuming both files have the same level of specificity, which ever file appears last in the code is what will be used.

For example, suppose the following CSS files:

/* file1.css */
#myid .myclass p { color: #000; }


/* file2.css */
#myid .myclass p { color: #f00; }

Those rules have the same specificity, so if you want the rule in file1.css to be applied then your markup would be:

<link rel="stylesheet" type="text/css" href="file2.css">
<link rel="stylesheet" type="text/css" href="file1.css">

And if you wanted the style from file2.css to be in effect you would need to do this:

<link rel="stylesheet" type="text/css" href="file1.css">
<link rel="stylesheet" type="text/css" href="file2.css">