W3C home > Mailing lists > Public > www-style@w3.org > July 2004

Re: [CSS21] selector's specificity issues.

From: Lachlan Hunt <lachlan.hunt@iinet.net.au>
Date: Thu, 08 Jul 2004 15:39:59 +1000
Message-ID: <40ECDE2F.4050608@iinet.net.au>
To: Andrew Fedoniouk <news@terrainformatica.com>
Cc: www-style@w3.org

Andrew Fedoniouk wrote:

> #1 -----------------------------------------------------------------
> 
> Algortihm described in [1] for counting style selector's specificity
> does not distinguish cases:
> 
> "ul li" and "ul>li"
> 
> Obviously second case is more strong/specific therefore it should have a
> bigger weight.

   No, they have the same specificity.  Where in the spec does it say 
otherwise?  The only reason "ul>li" would override "ul li" is if it 
comes later in the cascade.  Try this following test case:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>CSS Test: Specificty of Child vs Descendant Combinators</title>
       <style type="text/css"><!--/*--><![CDATA[/*><!--*/
		div#test1 p { color: red; }
		div#test1>p { color: green; }

		div#test2>p { color: red; }
		div#test2 p { color: green; }
       /*]]>*/--></style>

</head>

<body>
<div id="test1">
	<p>Test 1: Descendant Combinator before Child Combinator</p>
</div>

<div id="test2">
	<p>Test 2: Child Combinator before Descendant Combinator</p>
</div>
</body>
</html>

   Both should produce green text.  I tested in Firefox and IE, and got 
the expected results: Firefox passed, IE Failed miserably.

-- 
Lachlan Hunt

lachlan.hunt@lachy.id.au
http://www.lachy.id.au/
Received on Thursday, 8 July 2004 01:42:06 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:31 GMT