| 形式 | anchor(<anchor-name>? && <anchor-side>, <length-percentage>) |
|---|---|
| 値の詳細 | <anchor-name> = <dashed-ident> <anchor-side> = top | left | right | bottom | start | end | self-start | self-end | inside | outside | center | <percentage> |
| サポート | https://caniuse.com/mdn-css_types_anchor |
アンカーポジショニングにおいて配置ボックスの top, bottom, left, right を、アンカーのどの位置に隣接させるかを指定します。アンカーポジショニングに関する詳細は「とほほのアンカーポジショニング入門」を参照してください。
例えば次の例では、配置ボックスの top をアンカーの bottom に、配置ボックスの left をアンカーの right に隣接させます。配置ボックスの位置を指定するには他に position-area があります。position-area の方が直感的に指定することができます。
.my-positioned-box {
top: anchor(bottom);
left: anchor(right);
}
.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: 200px;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
padding: .2rem;
top: anchor(bottom);
left: anchor(left);
}
<div class="my-anchor">Anchor</div> <div class="my-positioned-box">Positioned Box</div>