cascade-highlight-001.html (1878B)
1 <!DOCTYPE html> 2 3 <meta charset="UTF-8"> 4 5 <title>CSS Pseudo-Elements Test: higher specificity of selectors (Example 11)</title> 6 7 <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/"> 8 <link rel="help" href="https://www.w3.org/TR/css-pseudo-4/#highlight-cascade"> 9 <link rel="match" href="cascade-highlight-001-ref.html"> 10 11 <!-- 12 Example 11 is 13 https://www.w3.org/TR/css-pseudo-4/#example-c35bf49a 14 --> 15 16 <meta name="assert" content="This test is an adaptation (or modified version) of Example 11 (#example-c35bf49a). The 'div > span::selection' selector has an higher specificity than the 'span::selection' selector."> 17 18 <link rel="stylesheet" href="../support/highlights.css"> 19 <style> 20 div 21 { 22 font-size: 300%; 23 } 24 25 div::selection 26 { 27 background-color: green; 28 color: yellow; 29 } 30 31 div > span::selection 32 /* 33 count the number of element names and pseudo-elements in the selector (= d) 34 a=0 b=0 c=0 d=3 -> specificity = 0,0,0,3 35 */ 36 { 37 background-color: green; 38 } 39 40 span::selection 41 /* 42 count the number of element names and pseudo-elements in the selector (= d) 43 a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 44 */ 45 { 46 background-color: red; 47 color: yellow; 48 } 49 </style> 50 51 <script> 52 function startTest() 53 { 54 var targetRange = document.createRange(); 55 /* We first create an empty range */ 56 targetRange.selectNodeContents(document.getElementById("test")); 57 /* Then we set the range boundaries to the children of div#test */ 58 window.getSelection().addRange(targetRange); 59 /* Finally, we now select such range of content */ 60 } 61 </script> 62 63 <body onload="startTest();"> 64 65 <p>Test passes if background color of "Text sample" is green and <strong>not red</strong>. 66 67 <div id="test" class="highlight_reftest">Text <span>sample</span></div>