Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-position/position-sticky-dynamic-ancestor-001.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Dynamic sticky position change doesn't break inner sticky positioned items</title>
<link rel="author" title="Emilio Cobos" href="mailto:emilio@crisal.io">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body {
margin: 0;
display: flex;
}
#content {
border: 10px dashed gray;
height: 600vh;
}
#sidebar {
align-self: start;
background-color: white;
border: 10px dashed gray;
top: 0;
}
#sidebar-header {
position: sticky;
top: 0;
background-color: rgba(255, 0, 0, .5);
}
#sidebar-content {
padding: 5px;
height: 200vh;
}
</style>
<div id=content>
CONTENT
</div>
<div id=sidebar>
<div id=sidebar-header>
SIDEBAR TOP STICKY
</div>
<div id=sidebar-content>
SIDEBAR CONTENT
</div>
</div>
<script>
let sidebar = document.getElementById("sidebar");
let sidebarHeader = document.getElementById("sidebar-header");
test(function() {
// Make the header and sidebar stick.
window.scrollTo(0, 100);
assert_less_than(sidebar.getBoundingClientRect().top, 0, "Sidebar should not be stuck (yet)");
assert_equals(sidebarHeader.getBoundingClientRect().top, 0, "Sidebar header should be stuck");
sidebar.style.position = "sticky";
assert_equals(sidebar.getBoundingClientRect().top, 0, "Sidebar should be stuck now");
assert_equals(sidebarHeader.getBoundingClientRect().top, 10, "Sidebar header should be stuck under sidebar border");
});
</script>