| 形式 | anchor-size([ <anchor-name> || <anchor-size> ]? , <length-percentage>) |
|---|---|
| 値の詳細 | <anchor-name> = <dashed-ident> <anchor-size> = width | height | block | inline | self-block | self-inline |
| サポート | https://caniuse.com/mdn-css_types_anchor-size |
アンカーポジショニングにおいて配置ボックスの大きさを決める際にアンカーの大きさを参照します。アンカーポジショニングに関する詳細は「とほほのアンカーポジショニング入門」を参照してください。
anchor-name で指定したアンカー名を指定します。下記の例では配置ボックスの横幅をアンカーの3倍、高さをアンカーの2倍に設定しています。
.my-anchor {
anchor-name: --my-anchor;
position: relative;
top: 20px;
left: 100px;
height: 24px;
line-height: 24px;
width: 120px;
background-color: #339;
color: #fff;
text-align: center;
}
.my-positioned-box {
position-anchor: --my-anchor;
position: absolute;
width: calc(anchor-size(width) * 3);
height: calc(anchor-size(height) * 2);
background-color: #eee;
border: 1px solid #ccc;
padding: .2rem;
position-area: bottom span-right;
}
<div class="my-anchor">Anchor</div> <div class="my-positioned-box">Positioned Box</div>