tags:

views:

287

answers:

3

I would like to override setting that already defined with selecting parent selector but I don't know how. Say, there are 2 pages on a website like the following...

-Home page-
<body><h1 class="sifr">Home</h1></body>

-About page-
<body class="about"><h1 class="sifr">About</h1></body>

then, I have these in sirf-config.js...

sIFR.replace(fontname, { selector: 'h1.sifr', css: '.sIFR-root { color: #666666; font-size:29px; }' });

sIFR.replace(fontname, { selector: 'body.about h1.sifr', css: '.sIFR-root { color: #FFFFFF; font-size:29px; }' });

but it doesn't work...

If anybody help me I would appreciate.

A: 

Check the order your loading CSS vs issuing the replace commands ...

Robert French
A: 

I don't use Sifr, so I don't know exactly how it works. I assume that the code creates CSS code like this:

h1.sifr { color: #666666; font-size: 29px; }
body.about h1.sifr { color: #FFFFFF; font-size: 29px; }

If it does, that will override the color style for the heading in the about page, as the selector for the second line is more specific than the selector in the first line.

You can read more about specificity here.

If it doesn't work, it's because there is something in your code that doesn't look like you think it does, and it may very well be something in some other part of your code that you haven't shown here that is causing the problem.

You can use the Firebug plugin in Firefox to inspect the elements in the page to see exactly which css is affecting each element.

Guffa
A: 

Run the replacements for body.about h1.sifr before h1.sifr. sIFR doesn't calculate specificity but executes the replacements in-order. Replacing h1.sifr replaces all such elements, so body.about h1.sifr only finds elements that have already been replaced.

Mark Wubben
Thank you very much. You are star! I didn't know about this but now i like sifr more and more!
Takashi Irie