Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anttijk committed May 2, 2023
1 parent a76b8a4 commit 74232c7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions css/css-contain/container-queries/container-units-content-box.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!doctype html>
<title>Container Relative Units: evaluate against the content box</title>
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#container-lengths">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
.size {
container-type: size;
width:100px;
height:50px;
border: 10px solid green;
padding: 10px;
}
.border-box {
box-sizing: border-box;
}
</style>
<div id=ref></div>
<div class="size">
<div id=child></div>
</div>
<div class="size border-box">
<div id=child2></div>
</div>
<script>
setup(() => assert_implements_container_queries());

function assert_unit_equals(element, actual, expected) {
try {
element.style.padding = actual;
ref.style.padding = expected;
assert_equals(getComputedStyle(element).paddingLeft,
getComputedStyle(ref).paddingLeft);
} finally {
element.style = '';
ref.style = '';
}
}

test(function() {
assert_unit_equals(child, '10cqi', '10px');
assert_unit_equals(child, '10cqw', '10px');
assert_unit_equals(child, '10cqb', '5px');
assert_unit_equals(child, '10cqh', '5px');
assert_unit_equals(child, '10cqmin', '5px');
assert_unit_equals(child, '10cqmax', '10px');
}, 'Container units are relative to the content box of the container');

test(function() {
assert_unit_equals(child2, '10cqi', '6px');
assert_unit_equals(child2, '10cqw', '6px');
assert_unit_equals(child2, '10cqb', '1px');
assert_unit_equals(child2, '10cqh', '1px');
assert_unit_equals(child2, '10cqmin', '1px');
assert_unit_equals(child2, '10cqmax', '6px');
}, 'Container units are relative to the content box of the container (box-sizing: border-box)');
</script>

0 comments on commit 74232c7

Please sign in to comment.