Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-conditional/container-queries/style-query-with-container-name-custom-change.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>CSS Container Queries Test: named container style() query toggling.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
.outer {
container-name: my-named-container;
--length: 200px;
}
.inner {
background-color: red;
}
@container my-named-container (style(--length: 200px)) {
.inner {
background-color: green;
}
}
</style>
<div id="dut">
<div id="child" class="inner"></div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(child).backgroundColor, "rgb(255, 0, 0)");
}, "Initially container rule does not match.");
test(() => {
dut.classList.add("outer");
assert_equals(getComputedStyle(child).backgroundColor, "rgb(0, 128, 0)");
}, "Container rule matches and inner changes colour");
test(() => {
dut.classList.remove("outer");
assert_equals(getComputedStyle(child).backgroundColor, "rgb(255, 0, 0)");
}, "Container rule stops matching and inner changes colour back");
</script>