summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/anchor-center-offset-change.html
blob: fa383154da6f7c8a52a61f76333dedda7c309ef4 (plain)
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
<!DOCTYPE html>
<title>CSS Anchor Positioning Test: Dynamically change the anchor-center position</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#anchor-center">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  #cb {
    position: relative;
    width: 200px;
    height: 200px;
  }
  #anchor {
    width: 100px;
    height: 100px;
    anchor-name: --anchor;
  }
  #anchored {
    position: absolute;
    width: 100px;
    height: 100px;
    position-anchor: --anchor;
    align-self: anchor-center;
    left: anchor(--unknown right, 0px);
  }
</style>
<div id="cb">
  <div id="anchor"></div>
  <div id="anchored"></div>
</div>
<script>
  test(() => {
    assert_equals(anchored.offsetLeft, 0);
    assert_equals(anchored.offsetTop, 0);
  }, "Anchored initially have the same width as the anchor");

  test(() => {
    anchor.style.height = "200px";
    assert_equals(anchored.offsetLeft, 0);
    assert_equals(anchored.offsetTop, 50);
  }, "Increase the height of the anchor to move the anchor-center offset");
</script>