Outlining CSS and specificity

3 views
Skip to first unread message

George Huger

unread,
Nov 3, 2010, 2:46:41 PM11/3/10
to mod-pagespeed-discuss
Moving inline CSS rules to external files changes their specificity.
Should this be added to the risks page for this filter?

For example, if we had the following code in an external CSS file:

#main p
{
color: red;
}

And this HTML:

<div id="main">
<p style="color: green">Hello World</p>
</div>

We would expect the text Hello World to be colored green. However if
we move the inline rule to an external file, the #main p rule in the
first CSS file will now be more specific and it will "win", causing
Hello World to be colored red.

More info on CSS specificity rules:

http://www.molly.com/2005/10/06/css2-and-css21-specificity-clarified/

Cheers,
George

Joshua Marantz

unread,
Nov 3, 2010, 2:48:31 PM11/3/10
to mod-pagesp...@googlegroups.com
Thanks for the note, George.  We'll certainly add that to the "risks" section.  Good catch.

-Josh
Reply all
Reply to author
Forward
0 new messages