阿超
>
position-try-fallbacks
教育成功的秘密,在于尊重学生。——爱默生
昨天我们聊到了
position-try | 阿超
今天是它的拓展,我们通过@position-try
定义移动到的位置,然后用position-try
使用
语法例如:
1 2 3 4 5 6 7 8 9 10
| @position-try --my-custom-position { position-area: top left; width: 50px; }
.target { position: absolute; position-area: top right; position-try-fallbacks: --my-custom-position; }
|
我们这里还是用昨天的例子,定义一个
1 2 3 4 5
| @position-try --compact-target { height: 40px; margin: 0px; }
|
然后我们使用:
1 2 3 4 5 6
| @supports (position-try: inset-area(bottom)) { .target { position-try: --compact-target, inset-area(bottom); } }
|
效果:
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
| <style> @position-try --compact-target { height: 40px; margin: 0px; }
.anchor { anchor-name: --my-anchor;
height: 80px; aspect-ratio: 1; }
.target { position: absolute; position-anchor: --my-anchor; position-area: top;
width: 80px; aspect-ratio: 1; }
#mainstay, #article { position: initial !important; }
.tmp-container { display: flex; align-items: center; justify-content: center;
height: 200vh; font-family: monospace; }
.anchor { display: flex; align-items: center; justify-content: center;
border-radius: 10px; background-color: #ffbd59; }
.target { display: flex; align-items: center; justify-content: center;
border-radius: 10px; background-color: #cb6ce6; }
@supports (position-try: inset-area(bottom)) { .target { position-try: --compact-target, inset-area(bottom); } }
@supports (inset-area: top) { .target { inset-area: top; } } </style> <div class="tmp-container"> <div class="anchor">anchor</div> <div class="target">target</div> </div>
|