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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
<!DOCTYPE html>
<title>CSS Anchor Positioning: position-try-order behavior with position-area</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#position-try-order-property">
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#position-area">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
Note: This test is the position-area version of position-try-order-basic.html.
-->
<style>
#cb {
position: absolute;
width: 400px;
height: 400px;
border: 1px solid black;
}
#anchor {
position: absolute;
left: 150px;
top: 200px;
width: 150px;
height: 150px;
background-color: coral;
anchor-name: --a;
}
#target, #ref {
position: absolute;
left: 450px; /* force fallback */
width: 40px;
height: 40px;
background-color: skyblue;
position-anchor: --a;
/* Note: align/justify is for cosmetic/debugging reasons only,
it should not have any effect on the result. */
align-self: start;
justify-self: start;
}
#ref {
background-color: seagreen;
}
/*
The IMCB for --right is the whole area to the right of the anchor, and similarly
for --left, etc.
┌──────────────┐
│ xxxx│
│ xxxx│
│ ┌────┐xxxx│
│ │ │xxxx│
│ └────┘xxxx│
│ xxxx│
│ xxxx│
└──────────────┘
**/
@position-try --right {
inset: unset;
position-area: right;
}
@position-try --left {
inset: unset;
position-area: left;
}
@position-try --top {
inset: unset;
position-area: top;
}
@position-try --bottom {
inset: unset;
position-area: bottom;
}
/*
The IMCB for --right-sweep is the area that would be "swept" by the anchor if it
moved right, and similarly for --left-sweep, etc.
┌──────────────┐
│ │
│ │
│ ┌────┐xxxx│
│ │ │xxxx│
│ └────┘xxxx│
│ │
│ │
└──────────────┘
*/
@position-try --right-sweep {
inset: unset;
position-area: right center;
}
@position-try --left-sweep {
inset: unset;
position-area: left center;
}
@position-try --bottom-sweep {
inset: unset;
position-area: bottom center;
}
@position-try --top-sweep {
inset: unset;
position-area: top center;
}
</style>
<style id=style>
</style>
<div id=cb>
<div id=anchor></div>
<div id=target></div>
<div id=ref></div>
</div>
<script>
// Test that an element with the specified `position_try` gets the same
// position as a reference element with `position_try_expected`.
function test_position_area_order(position_try, position_try_expected) {
test((t) => {
style.textContent = `
#target {
position-try: ${position_try};
}
#ref {
position-try: ${position_try_expected};
}
`;
assert_true(CSS.supports('position-try', 'normal --x'));
assert_equals(target.offsetLeft, ref.offsetLeft, 'offsetLeft');
assert_equals(target.offsetTop, ref.offsetTop, 'offsetTop');
}, `${position_try} | ${position_try_expected}`);
}
// Note: --right, --left, --top, and --bottom all fit, but have different
// inset-modifed containing blocks.
test_position_area_order('--right', '--right');
test_position_area_order('--left', '--left');
test_position_area_order('--top', '--top');
test_position_area_order('--bottom', '--bottom');
// position-try-order:normal just picks the first fallback.
test_position_area_order('--right, --left, --bottom, --top', '--right');
test_position_area_order('normal --right, --left, --bottom, --top', '--right');
test_position_area_order('normal --top, --left, --bottom, --right', '--top');
// --right and --left have the same IMCB block-size.
test_position_area_order('most-block-size --right, --left', '--right');
test_position_area_order('most-height --right, --left', '--right');
// --left has more inline-size than --right.
test_position_area_order('most-inline-size --right, --left', '--left');
test_position_area_order('most-width --right, --left', '--left');
// --bottom and --top have the same IMCB inline-size.
test_position_area_order('most-inline-size --bottom, --top', '--bottom');
test_position_area_order('most-width --bottom, --top', '--bottom');
// --top has more block-size than --bottom.
test_position_area_order('most-block-size --bottom, --top', '--top');
test_position_area_order('most-height --bottom, --top', '--top');
// --bottom/--top has more IMBC inline-size than --right/--left.
test_position_area_order('most-inline-size --right, --left, --bottom, --top', '--bottom');
test_position_area_order('most-inline-size --right, --left, --top, --bottom', '--top');
// --right/--left has more IMBC block-size than --bottom/--top.
test_position_area_order('most-block-size --bottom, --top, --right, --left', '--right');
test_position_area_order('most-block-size --bottom, --top, --left, --right', '--left');
// --left-sweep and --bottom-sweep has the same IMBC inline-size ...
test_position_area_order('most-inline-size --left-sweep, --bottom-sweep', '--left-sweep');
test_position_area_order('most-inline-size --bottom-sweep, --left-sweep', '--bottom-sweep');
// ... but not the same block-size.
test_position_area_order('most-block-size --left-sweep, --bottom-sweep', '--left-sweep');
test_position_area_order('most-block-size --bottom-sweep, --left-sweep', '--left-sweep');
test_position_area_order('most-inline-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep', '--left-sweep');
test_position_area_order('most-block-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep', '--top-sweep');
// NOTE: the css-anchor-position-1 spec requires that only a minimum of five
// fallback positions be respected. So this test, while intended to test across
// all 8 fallbacks, intentionally leaves off 3 of them.
test_position_area_order(`most-inline-size
--right-sweep, --left-sweep, --bottom-sweep, --top-sweep,
/* --right, --left, --bottom, --top */
--bottom
`, '--bottom');
// NOTE: the css-anchor-position-1 spec requires that only a minimum of five
// fallback positions be respected. So this test, while intended to test across
// all 8 fallbacks, intentionally leaves off 3 of them.
test_position_area_order(`most-block-size
--right-sweep, --left-sweep, --bottom-sweep, --top-sweep,
/* --right, --left, --bottom, --top */
--right
`, '--right');
</script>
|