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-custom-attr-change.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>CSS Container Queries Test: style() query with attr() for unregistered custom property</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
#target {
color: red;
}
@container style(--my-props: attr(myAttr)) {
#target {
color: green;
}
}
#container {
--my-props: "correct"
}
</style>
<div id="container" myAttr="wrong">
<div id="target">Should be green</div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(target).color, "rgb(255, 0, 0)");
}, "Initially, container does not match. Target is red.");
test(() => {
container.setAttribute("myAttr", "correct");
assert_equals(getComputedStyle(target).color, "rgb(0, 128, 0)");
}, "Changing myAttribute to 'correct' in container makes target color green");
</script>