summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/anchor-getComputedStyle-001.html
blob: 6d77cf9a9d4cc34f5b2c787502f0d7753ff41c94 (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
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests that getComputedStyle() resolves anchor functions</title>
<link rel="help" href="https://drafts4.csswg.org/css-anchor-position-1">
<link rel="help" href="https://drafts.csswg.org/cssom/#resolved-value">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.vrl { writing-mode: vertical-rl; }
.htb { writing-mode: horizontal-tb; }
.ltr { direction: ltr; }
.rtl { direction: rtl; }

.cb {
  transform: scale(1);
  width: 200px;
  height: 150px;
  outline: 1px dashed black;
}

.padding-10 {
  box-sizing: border-box;
  padding: 10px;
}

.anchor {
  width: 40px;
  height: 30px;
  background: orange;
  anchor-name: --a;
  position: relative;
  top: 50px;
  left: 60px;
}

.anchored-topleft {
  position: absolute;
  width: anchor-size(--a width);
  height: anchor-size(--a height);
  bottom: anchor(--a top);
  right: anchor(--a left);
  background: lime;
}

.anchored-bottomright {
  position: absolute;
  width: anchor-size(--a width);
  height: anchor-size(--a height);
  top: anchor(--a bottom);
  left: anchor(--a right);
  background: lime;
}
</style>

<div class=cb id=test1>
  <div class=anchor></div>
  <div class=anchored-topleft></div>
  <div class=anchored-bottomright></div>
</div>
<script>
test(() => {
  const container = document.getElementById('test1');

  const topleft = container.querySelector('.anchored-topleft');
  assert_equals(getComputedStyle(topleft).bottom, '100px');
  assert_equals(getComputedStyle(topleft).right, '140px');
  assert_equals(getComputedStyle(topleft).width, '40px');
  assert_equals(getComputedStyle(topleft).height, '30px');

  const bottomright = container.querySelector('.anchored-bottomright');
  assert_equals(getComputedStyle(bottomright).top, '80px');
  assert_equals(getComputedStyle(bottomright).left, '100px');
  assert_equals(getComputedStyle(bottomright).width, '40px');
  assert_equals(getComputedStyle(bottomright).height, '30px');
}, 'Basic case');
</script>

<div class="cb vrl" id=test2>
  <div class=anchor></div>
  <div class="anchored-topleft htb ltr"></div>
  <div class="anchored-bottomright htb rtl"></div>
</div>
<script>
test(() => {
  const container = document.getElementById('test2');

  const topleft = container.querySelector('.anchored-topleft');
  assert_equals(getComputedStyle(topleft).bottom, '100px');
  assert_equals(getComputedStyle(topleft).right, '-20px');
  assert_equals(getComputedStyle(topleft).width, '40px');
  assert_equals(getComputedStyle(topleft).height, '30px');

  const bottomright = container.querySelector('.anchored-bottomright');
  assert_equals(getComputedStyle(bottomright).top, '80px');
  assert_equals(getComputedStyle(bottomright).left, '260px');
  assert_equals(getComputedStyle(bottomright).width, '40px');
  assert_equals(getComputedStyle(bottomright).height, '30px');
}, 'Mixed writing modes and directions');
</script>

<div class="cb padding-10" id=test3>
  <div class=anchor></div>
  <div class=anchored-topleft></div>
  <div class=anchored-bottomright></div>
</div>
<script>
test(() => {
  const container = document.getElementById('test3');

  const topleft = container.querySelector('.anchored-topleft');
  assert_equals(getComputedStyle(topleft).bottom, '90px');
  assert_equals(getComputedStyle(topleft).right, '130px');
  assert_equals(getComputedStyle(topleft).width, '40px');
  assert_equals(getComputedStyle(topleft).height, '30px');

  const bottomright = container.querySelector('.anchored-bottomright');
  assert_equals(getComputedStyle(bottomright).top, '90px');
  assert_equals(getComputedStyle(bottomright).left, '110px');
  assert_equals(getComputedStyle(bottomright).width, '40px');
  assert_equals(getComputedStyle(bottomright).height, '30px');
}, 'With containing block padding');
</script>