| 12
 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
 
 | <!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-try-fallbacks: --f1, --f2, --f3, --f4;
  width: 40px;
  height: 15px;
  margin: 5px;
  background: orange;
  /* Position to the right of the anchor. */
  left: anchor(--a1 right);
  top: anchor(--a1 top);
}
@position-try --f1 {
  inset: auto;
  /* Position to the left of the anchor. */
  right: anchor(--a1 left);
  top: anchor(--a1 top);
}
@position-try --f2 {
  inset: auto;
  /* Position to the bottom of the anchor. */
  left: anchor(--a1 left);
  top: anchor(--a1 bottom);
}
@position-try --f3 {
  inset: auto;
  /* Position to the top of the anchor. */
  left: anchor(--a1 left);
  bottom: anchor(--a1 top);
}
@position-try --f4 {
  inset: auto;
  /* 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 base style 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 first `@position-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 2nd `@position-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 3rd `@position-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 `@position-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 base style 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=40 data-expected-height=15></div>
  </div>
</body>
 |