File: inherit-function-basic.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (139 lines) | stat: -rw-r--r-- 3,310 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<title>CSS Values: The inherit() function (basic behavior)</title>
<link rel="help" href="https://drafts.csswg.org/css-values-5/#inherit-notation">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<main id=main>
</main>

<template id=inherit_immediate_parent>
  <style>
    #parent {
      --z: 2;
    }
    #target {
      --z: 13;
      z-index: inherit(--z);
    }
  </style>
  <div id=parent>
    <div id=target>
    </div>
  </div>
</template>
<script>
  test((t) => {
    main.append(inherit_immediate_parent.content.cloneNode(true));
    t.add_cleanup(() => { main.replaceChildren(); });
    assert_equals(getComputedStyle(target).zIndex, '2');
  }, 'inherit() on value set on parent');
</script>

<template id=inherit_ancestor>
  <style>
    :root {
      --z: 2;
    }
    #foo {
      --z: 13;
      z-index: inherit(--z);
    }
  </style>
  <div id=foo>
  </div>
</template>
<script>
  test((t) => {
    main.append(inherit_ancestor.content.cloneNode(true));
    t.add_cleanup(() => { main.replaceChildren(); });
    assert_equals(getComputedStyle(foo).zIndex, '2');
  }, 'inherit() on value set on ancestor');
</script>

<template id=inherit_fallback>
  <style>
    #foo {
      --z: 13;
      z-index: inherit(--z, 4);
    }
  </style>
  <div id=foo>
  </div>
</template>
<script>
  test((t) => {
    main.append(inherit_fallback.content.cloneNode(true));
    t.add_cleanup(() => { main.replaceChildren(); });
    assert_equals(getComputedStyle(foo).zIndex, '4');
  }, 'inherit(), no value set on parent');
</script>

<template id=inherit_accumulate_values>
  <style>
    #e1 { --v: e1; }
    #e2 { --v: e2 inherit(--v); }
    #e3 { --v: e3 inherit(--v); }
  </style>
  <div id=e1>
    <div id=e2>
      <div id=e3>
      </div>
    </div>
  </div>
</template>
<script>
  test((t) => {
    main.append(inherit_accumulate_values.content.cloneNode(true));
    t.add_cleanup(() => { main.replaceChildren(); });
    assert_equals(getComputedStyle(e3).getPropertyValue('--v'), 'e3 e2 e1');
  }, 'inherit(), accumulating values');
</script>

<template id=inherit_accumulate_font_size>
  <style>
    @property --f {
      syntax: "<length>";
      inherits: false;
      initial-value: 0px;
    }
    #e1 { font-size: 3px; --f: 1em; }
    #e2 { font-size: 5px; --f: calc(1em + inherit(--f)); }
    #e3 { font-size: 7px; --f: calc(1em + inherit(--f)); }
  </style>
  <div id=e1>
    <div id=e2>
      <div id=e3>
      </div>
    </div>
  </div>
</template>
<script>
  test((t) => {
    main.append(inherit_accumulate_font_size.content.cloneNode(true));
    t.add_cleanup(() => { main.replaceChildren(); });
    assert_equals(getComputedStyle(e3).getPropertyValue('--f'), '15px');
  }, 'inherit(), accumulating font-size');
</script>

<template id=inherit_within_if>
  <style>
    #parent {
      --z: 2;
    }
    #target {
      --z: 13;
      z-index: if(style(--z > inherit(--z)):4; else:7);
    }
  </style>
  <div id=parent>
    <div id=target>
    </div>
  </div>
</template>
<script>
  test((t) => {
    main.append(inherit_within_if.content.cloneNode(true));
    t.add_cleanup(() => { main.replaceChildren(); });
    assert_equals(getComputedStyle(target).zIndex, '4');
  }, 'inherit() can be used within if()');
</script>