File: has-specificity.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (50 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<title>Specificity for complex :has selectors</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://drafts.csswg.org/selectors/#specificity-rules">
<style>
  main :has(#foo) { --t0:PASS; }
  main :has(.foo) { --t0:FAIL; }

  main :has(span#foo) { --t1:PASS; }
  main :has(#foo) { --t1:FAIL; }

  main :has(.bar, #foo) { --t2:FAIL; }
  main :has(#foo, .bar) { --t2:PASS; }

  main :has(.bar, #foo) { --t3:PASS; }
  main :has(.foo, .bar) { --t3:FAIL; }

  main :has(span + span) { --t4:PASS; }
  main :has(span) { --t4:FAIL; }

  main :has(span, li, #foo) { --t5:PASS; }
  main :has(span, li, p) { --t5:FAIL; }

  main div:has(.foo) { --t6:FAIL; }
  main div.baz { --t6:PASS; }

  main div.baz { --t7:FAIL; }
  main div:has(.foo) { --t7:PASS; }
</style>
<main id=main>
  <div id=div class=baz><p><span id=foo class=foo></span><span class=bar></span><li></li></p></div>
</main>
<script>
  function test_value(name, description) {
    test(function() {
      let actual = getComputedStyle(div).getPropertyValue(name);
      assert_equals(actual, 'PASS');
    }, description);
  }

  test_value('--t0', ':has(#foo) wins over :has(.foo)');
  test_value('--t1', ':has(span#foo) wins over :has(#foo)');
  test_value('--t2', ':has(.bar, #foo) has same specificity as :has(#foo, .bar)');
  test_value('--t3', ':has(.bar, #foo) wins over :has(.foo, .bar)');
  test_value('--t4', ':has(span + span) wins over :has(span)');
  test_value('--t5', ':has(span, li, p) wins over :has(span, lo, p)');
  test_value('--t6', 'latter .baz wins over :has(.foo)');
  test_value('--t7', 'latter :has(.foo) wins over .baz');
</script>