-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathquery-container-name.html
More file actions
64 lines (60 loc) · 1.87 KB
/
query-container-name.html
File metadata and controls
64 lines (60 loc) · 1.87 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
<!DOCTYPE html>
<title>@container: query container name, no query part</title>
<link rel="help" href="https://un5n798jx6qx6j0rmf2verhh.julianrbryant.com/css-conditional-5/#container-rule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#inner { container-name: --foo }
#outer { container-name: --bar }
#target {
--match-foo: no;
--match-bar: no;
--match-baz: no;
}
@container --foo { #target { --match-foo: yes; } }
@container --bar { #target { --match-bar: yes; } }
@container --baz { #target { --match-baz: yes; } }
</style>
<div id="outer">
<div id="inner">
<div id="target"></div>
</div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(target).getPropertyValue("--match-foo"), "yes");
}, "match closest named container");
test(() => {
assert_equals(getComputedStyle(target).getPropertyValue("--match-bar"), "yes");
}, "match ancestor named container");
test(() => {
assert_equals(getComputedStyle(target).getPropertyValue("--match-baz"), "no");
}, "no match for unused container name");
</script>
<style>
@container --in-shadow {
#slotted { --match-in-shadow: yes; }
}
</style>
<div id="host" style="container-name: --for-host">
<template shadowrootmode="open">
<style>
@container --for-host {
#in-shadow { --match-for-host: yes; }
}
</style>
<div style="container-name: --in-shadow">
<div id="in-shadow"></div>
<slot></slot>
</div>
</template>
<div id="slotted"></div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(slotted).getPropertyValue("--match-in-shadow"), "yes");
}, "match named container in shadow");
test(() => {
assert_equals(getComputedStyle(host.shadowRoot.querySelector("#in-shadow")).getPropertyValue("--match-for-host"), "yes");
}, "match named container in outer scope");
</script>