File: has-specificity.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (50 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (17)
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>