Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<title>@container-dependent elements respond to root metrics size changes</title>
<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#size-container">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
:root, body { font-size: 16px; }
#container {
container-type: size;
width: 20px;
}

#target { color: red; }
@container (width < 1rem) {
#target { color: green; }
}
</style>
<div id="container">
<div id="target"></div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(target).color, "rgb(255, 0, 0)");
}, "Initially, 1rem equals 16px, less than the container's width");

test(() => {
document.documentElement.style.fontSize = "30px";
assert_equals(getComputedStyle(target).color, "rgb(0, 128, 0)");
}, "Changing the :root font-size makes 1rem equal 30px, greater than the container's width");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<title>CSS Container Queries Test: style() query with em unit for registered custom property.</title>
<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#style-container">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
@property --length {
syntax: "<length>";
initial-value: 0px;
inherits: false;
}

#container {
font-size: 16px;
--length: 20px;
}

#target { color: red; }
@container style(--length: calc(1em + 10px)) {
#target { color: green; }
}
</style>
<div id="container">
<div id="target">Should be green</div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(target).color, "rgb(255, 0, 0)");
}, "Initially, 1em (16px) + 10px evaluates to 26px. Target does not match.");

test(() => {
container.style.fontSize = "10px";
assert_equals(getComputedStyle(target).color, "rgb(0, 128, 0)");
}, "Changing the container's font-size to 10px makes 1em (10px) + 10px evaluate to 20px. Target matches.");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>CSS Container Queries Test: named container style() query toggling.</title>
<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#style-container"/>
<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>
Loading