-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathcontents-rule.html
More file actions
134 lines (123 loc) · 3.1 KB
/
contents-rule.html
File metadata and controls
134 lines (123 loc) · 3.1 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
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
<!DOCTYPE html>
<html>
<head>
<title>CSS Mixins: The @contents rule</title>
<link rel="help" href="https://drafts.csswg.org/css-mixins-1/#contents-rule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<style>
@mixin --m1() {
@result {
@contents;
}
}
#e1 {
color: red;
@apply --m1 { color: green; }
}
</style>
<div id="e1">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e1');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Simple @contents with no fallback');
</script>
<style>
@mixin --m2() {
@result {
@contents
}
}
#e2 {
color: red;
@apply --m2 { color: green; }
}
</style>
<div id="e2">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e2');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Implicit semicolon after @contents, at end of block');
</script>
<style>
@mixin --m3() {
@result {
&.a {
@contents { color: blue; }
}
}
}
.b {
color: red;
@apply --m3 { color: green; }
}
</style>
<div class="a b" id="e3">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e3');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Block in @apply overrides fallback');
</script>
<style>
@mixin --m4() {
@result {
&.c {
@contents { color: green; }
}
}
}
.d {
color: red;
@apply --m4;
}
</style>
<div class="c d" id="e4">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e4');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Fallback is used if @apply has no block');
</script>
<style>
@mixin --m6() {
@result {
@contents { }
color: green;
}
}
#e6 {
@apply --m6;
}
</style>
<div id="e6">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e6');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Empty @contents block is allowed, but does nothing');
</script>
<style>
@mixin --m7() {
@result {
@contents;
color: green;
}
}
#e7 {
@apply --m7 {};
}
</style>
<div id="e7">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e7');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Empty @contents parameter does not crash');
</script>
</body>
</html>