summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/position-fallback-001.html
blob: d28c71ec6813000296012a4fcab8787dbb3e8f5d (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
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#fallback">
<link rel="author" href="mailto:kojii@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<script src="support/test-common.js"></script>
<style>
.cb {
  position: relative;
  width: 190px;
  height: 70px;
  background: yellow;
  border-bottom: 1px solid black;
}
.spacer {
  width: 1px;
  height: 20px;
}
.anchor1 {
  anchor-name: --a1;
  margin-left: 45px;
  width: 100px;
  height: 30px;
  background: blue;
}
.target {
  position: absolute;
  position-fallback: --fallback1;
  width: 40px;
  height: 15px;
  margin: 5px;
  background: orange;
}
@position-fallback --fallback1 {
  @try { /* 1: Position to the right of the anchor. */
    left: anchor(--a1 right);
    top: anchor(--a1 top);
  }
  @try { /* 2: Position to the left of the anchor. */
    right: anchor(--a1 left);
    top: anchor(--a1 top);
  }
  @try { /* 3: Position to the bottom of the anchor. */
    left: anchor(--a1 left);
    top: anchor(--a1 bottom);
  }
  @try { /* 4: Position to the top of the anchor. */
    left: anchor(--a1 left);
    bottom: anchor(--a1 top);
  }
  @try { /* 5: Position to the left with the narrower width. */
    left: anchor(--a1 right);
    top: anchor(--a1 top);
    width: 35px;
    height: 40px;
  }
}
</style>
<body onload="checkLayoutForAnchorPos('.target')">
  <!-- If the `cb` is wider, the 1st `@try` fits. -->
  <div class="cb" style="width: 195px">
    <div class="spacer"></div>
    <div class="anchor1"></div>
    <div class="target"
         data-offset-x=150 data-offset-y=25
         data-expected-width=40 data-expected-height=15></div>
  </div>
  <!-- If the `margin-left` is wider, the 2nd `@try` fits. -->
  <div class="cb">
    <div class="spacer"></div>
    <div class="anchor1" style="margin-left: 50px"></div>
    <div class="target"
         data-offset-x=5 data-offset-y=25
         data-expected-width=40 data-expected-height=15></div>
  </div>
  <!-- Without a spacer, the 3rd `@try` fits. -->
  <div class="cb">
    <div class="anchor1"></div>
    <div class="target"
         data-offset-x=50 data-offset-y=35
         data-expected-width=40 data-expected-height=15></div>
  </div>
  <!-- With two spacers, the 4th `@try` fits. -->
  <div class="cb">
    <div class="spacer"></div>
    <div class="spacer"></div>
    <div class="anchor1"></div>
    <div class="target"
         data-offset-x=50 data-offset-y=20
         data-expected-width=40 data-expected-height=15></div>
  </div>
  <!-- With a spacer, the last `@try` fits. -->
  <div class="cb">
    <div class="spacer"></div>
    <div class="anchor1"></div>
    <div class="target"
         data-offset-x=150 data-offset-y=25
         data-expected-width=35 data-expected-height=40></div>
  </div>
  <!-- If the `cb` is narrower, no rules fit. The last rule is used. -->
  <div class="cb" style="width: 185px">
    <div class="spacer"></div>
    <div class="anchor1"></div>
    <div class="target"
    data-offset-x=150 data-offset-y=25
         data-expected-width=35 data-expected-height=40></div>
  </div>
</body>