教育的胜利,可以压倒国民性。——爱默生
https://css-tricks.com/almanac/properties/p/position-try-fallbacks/
今天分享一个position-try
的css
属性
它就像字面意思是说:
位置-尝试
代表着 它在页面移动时尽可能尝试调整位置
举个栗子:
1 2 3 4 5 6 7
| .target { position: absolute; position-anchor: --my-anchor;
position-area: top; position-try-fallbacks: 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
| <style> .anchor { anchor-name: --my-anchor;
height: 80px; aspect-ratio: 1; }
.target { position: absolute; position-anchor: --my-anchor; position-area: top; position-try: bottom;
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: 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>
|