Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-anchor-position/position-anchor-match-parent-shadow.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Anchor Positioning: 'position-anchor: match-parent' across shadow tree boundaries</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#valdef-position-anchor-match-parent">
<link rel="author" href="mailto:jeroen.zwartepoorte@gmail.com">
<link rel="match" href="position-anchor-match-parent-shadow-ref.html">
<style>
.cases {
display: flex;
flex-wrap: wrap;
gap: 8px;
width: 642px;
}
.case {
position: relative;
box-sizing: border-box;
width: 122px;
height: 102px;
border: 1px solid silver;
}
.anchor {
position: absolute;
anchor-name: --a;
left: 20px;
top: 20px;
width: 50px;
height: 20px;
background: silver;
}
.host {
position: fixed;
inset: 0;
}
.probe {
position: fixed;
position-anchor: match-parent;
left: anchor(right, 20px);
top: anchor(bottom, 70px);
width: 20px;
height: 20px;
background: green;
}
</style>
<div class="cases">
<!-- Probe in a shadow tree; the host has a default anchor element. -->
<div class="case">
<div class="anchor"></div>
<div class="host" style="position-anchor: --a">
<template shadowrootmode="open">
<style>
.probe {
position: fixed;
position-anchor: match-parent;
left: anchor(right, 20px);
top: anchor(bottom, 70px);
width: 20px;
height: 20px;
background: green;
}
</style>
<div class="probe"></div>
</template>
</div>
</div>
<!-- Probe in a shadow tree; the host has no default anchor element. -->
<div class="case">
<div class="anchor"></div>
<div class="host" style="position-anchor: none">
<template shadowrootmode="open">
<style>
.probe {
position: fixed;
position-anchor: match-parent;
left: anchor(right, 20px);
top: anchor(bottom, 70px);
width: 20px;
height: 20px;
background: green;
}
</style>
<div class="probe"></div>
</template>
</div>
</div>
<!-- Slotted probe; the slot has no default anchor element. -->
<div class="case">
<div class="anchor"></div>
<div class="host" style="position-anchor: --a">
<template shadowrootmode="open">
<style>
slot {
display: block;
position: fixed;
inset: 0;
}
</style>
<slot></slot>
</template>
<div class="probe"></div>
</div>
</div>
<!-- Slotted probe; the slot itself uses 'match-parent'. -->
<div class="case">
<div class="anchor"></div>
<div class="host" style="position-anchor: --a">
<template shadowrootmode="open">
<style>
slot {
display: block;
position: fixed;
inset: 0;
position-anchor: match-parent;
}
</style>
<slot></slot>
</template>
<div class="probe"></div>
</div>
</div>
</div>