-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathrandom-item-nested.html
More file actions
39 lines (33 loc) · 1.56 KB
/
Copy pathrandom-item-nested.html
File metadata and controls
39 lines (33 loc) · 1.56 KB
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
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-values-5/#funcdef-random-item">
<link rel="author" title="Joanne Pan" href="https://github.com/J0pan">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="target"></div>
<script>
const target = document.getElementById('target');
// Nested random-item(): the inner function resolves after the outer selects it.
test(() => {
target.style.color = 'green';
target.style.color = 'random-item(fixed 0, random-item(fixed 0.999, red, rgb(1, 2, 3)), blue)';
assert_equals(getComputedStyle(target).color, 'rgb(1, 2, 3)');
}, 'random-item() nested inside random-item()');
// random-item() inside a var() reference.
test(() => {
target.style.cssText = '--list: random-item(fixed 0, rgb(1, 2, 3), rgb(4, 5, 6)); color: var(--list);';
assert_equals(getComputedStyle(target).color, 'rgb(1, 2, 3)');
}, 'random-item() resolved through var()');
// random-item() as a var() fallback.
test(() => {
target.style.cssText = 'color: var(--missing, random-item(fixed 0, rgb(7, 8, 9), blue));';
assert_equals(getComputedStyle(target).color, 'rgb(7, 8, 9)');
}, 'random-item() used as a var() fallback');
// random-item() feeding a shorthand property.
test(() => {
target.style.margin = '';
target.style.margin = 'random-item(fixed 0, 1px 2px, 3px 4px)';
const style = getComputedStyle(target);
assert_equals(style.marginTop, '1px');
assert_equals(style.marginRight, '2px');
}, 'random-item() expands in a shorthand property');
</script>