Commit b7430bcf authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Upstream sticky margin tests to WPT

Bug: 699244
Change-Id: Ie7d573bbda8e57cc718137f04a4b1fb0bde14355
Reviewed-on: https://chromium-review.googlesource.com/598589Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491745}
parent af38db52
<!DOCTYPE html>
<title>Reference for position:sticky elements should properly interact with margins</title>
<style>
.group {
display: inline-block;
position: relative;
width: 180px;
height: 400px;
}
.scroller {
width: 150px;
height: 300px;
overflow-y: scroll;
overflow-x: hidden;
}
.indicator {
position: relative;
background-color: green;
margin: 15px;
}
.box {
width: 100px;
height: 100px;
}
.padding {
height: 385px;
}
</style>
<script>
window.addEventListener('load', function() {
document.getElementById('scroller1').scrollTop = 0;
document.getElementById('scroller2').scrollTop = 60;
document.getElementById('scroller3').scrollTop = 120;
});
</script>
<div class="group">
<div id="scroller1" class="scroller">
<div class="indicator box" style="top: 0;"></div>
<div class="padding"></div>
</div>
</div>
<div class="group">
<div id="scroller2" class="scroller">
<div class="indicator box" style="top: 50px;"></div>
<div class="padding"></div>
</div>
</div>
<div class="group">
<div id="scroller3" class="scroller">
<div class="indicator box" style="top: 85px;"></div>
<div class="padding"></div>
</div>
</div>
<div>You should see three green boxes above. No red should be visible.</div>
<!DOCTYPE html>
<title>position:sticky elements should properly interact with margins</title>
<link rel="match" href="position-sticky-margins-ref.html" />
<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
<meta name="assert" content="position:sticky elements should ignore margins when sticking, but consider them when making sure sticky elements do not escape their containing block" />
<style>
.group {
display: inline-block;
position: relative;
width: 180px;
height: 400px;
}
.scroller {
position: relative;
width: 150px;
height: 300px;
overflow-y: scroll;
overflow-x: hidden;
}
.holder {
width: 130px;
height: 200px;
}
.sticky {
position: sticky;
background-color: green;
top: 5px;
margin: 15px;
}
.indicator {
left: 15px;
position: absolute;
background-color: red;
}
.box {
width: 100px;
height: 100px;
}
.padding {
height: 300px;
}
</style>
<script>
window.addEventListener('load', function() {
document.getElementById('scroller1').scrollTop = 0;
document.getElementById('scroller2').scrollTop = 60;
document.getElementById('scroller3').scrollTop = 120;
});
</script>
<!-- Before sticking, the margin should be obeyed. -->
<div class="group">
<div id="scroller1" class="scroller">
<div class="indicator box" style="top: 15px;"></div>
<div class="holder">
<div class="sticky box"></div>
</div>
<div class="padding"></div>
</div>
</div>
<!-- Whilst stuck, the margin is irrelevant. -->
<div class="group">
<div id="scroller2" class="scroller">
<div class="indicator box" style="top: 65px;"></div>
<div class="holder">
<div class="sticky box"></div>
</div>
<div class="padding"></div>
</div>
</div>
<!-- The margin does count when making sure the sticky element does not escape
its containing block. -->
<div class="group">
<div id="scroller3" class="scroller">
<div class="indicator box" style="top: 100px;"></div>
<div class="holder">
<div class="sticky box"></div>
</div>
<div class="padding"></div>
</div>
</div>
<div>You should see three green boxes above. No red should be visible.</div>
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
.group {
display: inline-block;
position: relative;
width: 180px;
height: 500px;
}
.container {
position: relative;
width: 150px;
height: 400px;
border: 2px solid black;
padding: 5px;
}
.box {
width: 120px;
height: 120px;
}
.sticky {
position: relative;
background-color: green;
}
.indicator {
position: absolute;
top: 0;
left: 37px;
background-color: red;
}
</style>
</head>
<body>
<!-- auto margins -->
<div class="group" style="top: -300px">
<div class="indicator box" style="top: 110px;"></div>
<div class="container">
<div class="sticky box" style="margin: auto; top: 280px"></div>
</div>
</div>
<!-- px margins -->
<div class="group" style="top: -300px">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box" style="margin: 20px; top: 240px"></div>
</div>
</div>
<!-- % margins -->
<div class="group" style="top: -300px">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box" style="margin: 20%; top: 220px"></div>
</div>
</div>
<!-- % margins -->
<div class="group" style="top: -300px">
<div class="indicator box" style="top: 37px;"></div>
<div class="container" style="width: 200px;">
<div class="sticky box" style="margin: 20%; top: 200px"></div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<script>
if (window.internals) {
internals.settings.setCSSStickyPositionEnabled(true);
}
</script>
<html>
<head>
<style>
body {
margin: 0;
height: 2000px;
overflow: hidden; /* hide scrollbars */
}
.group {
display: inline-block;
position: relative;
width: 180px;
height: 500px;
}
.container {
width: 150px;
height: 400px;
border: 2px solid black;
padding: 5px;
}
.box {
width: 120px;
height: 120px;
}
.sticky {
position: sticky;
top: 10px;
background-color: green;
}
.indicator {
position: absolute;
top: 0;
left: 37px;
background-color: red;
}
</style>
<script>
function doTest()
{
window.scrollTo(0, 300);
}
window.addEventListener('load', doTest, false);
</script>
</head>
<body>
<!-- auto margins -->
<div class="group">
<div class="indicator box" style="top: 110px;"></div>
<div class="container">
<div class="sticky box" style="margin: auto;"></div>
</div>
</div>
<!-- px margins -->
<div class="group">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box" style="margin: 20px;"></div>
</div>
</div>
<!-- % margins -->
<div class="group">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box" style="margin: 20%;"></div>
</div>
</div>
<!-- % margins -->
<div class="group">
<div class="indicator box" style="top: 37px;"></div>
<div class="container" style="width: 200px;">
<div class="sticky box" style="margin: 20%;"></div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
overflow: hidden; /* hide scrollbars */
}
.group {
position: relative;
width: 500px;
height: 200px;
}
.container {
position: relative;
width: 400px;
height: 180px;
outline: 2px solid black;
}
.box {
width: 200px;
height: 180px;
}
.sticky {
position: absolute;
background-color: green;
}
</style>
</head>
<body>
<div class="group" style="left: -100px">
<div class="container">
<div class="sticky box" style="right: 0;"></div>
</div>
</div>
<div class="group" style="left: -100px">
<div class="container">
<div class="sticky box" style="right: 20px;"></div>
</div>
</div>
<div class="group" style="left: -100px">
<div class="container">
<div class="sticky box" style="right: 80px"></div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<script>
if (window.internals) {
internals.settings.setCSSStickyPositionEnabled(true);
}
</script>
<html>
<head>
<style>
body {
margin: 0;
width: 2000px;
overflow: hidden; /* hide scrollbars */
}
.group {
position: relative;
width: 500px;
height: 200px;
}
.container {
width: 400px;
height: 180px;
outline: 2px solid black;
}
.box {
width: 200px;
height: 180px;
}
.sticky {
position: sticky;
left: 100px;
background-color: green;
}
</style>
<script>
function doTest()
{
window.scrollTo(300, 0);
}
window.addEventListener('load', doTest, false);
</script>
</head>
<body>
<div class="group" style="left: 200px">
<div class="container">
<div class="sticky box" style="margin: 0 auto;"></div>
</div>
</div>
<div class="group" style="left: 200px">
<div class="container">
<div class="sticky box" style="margin: 0 20px;"></div>
</div>
</div>
<div class="group" style="left: 200px">
<div class="container">
<div class="sticky box" style="margin: 0 20%;"></div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
.group {
display: inline-block;
position: relative;
width: 250px;
height: 500px;
}
.container {
width: 200px;
height: 400px;
border: 12px solid black;
padding: 5px;
}
.box {
width: 160px;
height: 160px;
}
.sticky {
position: relative;
margin: 20px;
background-color: green;
}
.indicator {
position: absolute;
top: 0;
left: 37px;
background-color: red;
}
</style>
</head>
<body>
<div class="group" style="top: -100px;">
<div class="indicator box" style="top: 110px;"></div>
<div class="container">
<div class="sticky box" style="top: 73px"></div>
</div>
</div>
<div class="group" style="top: 0">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box"></div>
</div>
</div>
<div class="group" style="top: 100px">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box"></div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<script>
if (window.internals) {
internals.settings.setCSSStickyPositionEnabled(true);
}
</script>
<html>
<head>
<style>
body {
margin: 0;
height: 2000px;
overflow: hidden; /* hide scrollbars */
}
.group {
display: inline-block;
position: relative;
width: 250px;
height: 500px;
}
.container {
width: 200px;
height: 400px;
border: 12px solid black;
padding: 5px;
}
.box {
width: 160px;
height: 160px;
}
.sticky {
position: sticky;
top: 10px;
margin: 20px;
background-color: green;
}
.indicator {
position: absolute;
top: 0;
left: 37px;
background-color: red;
}
</style>
<script>
function doTest()
{
window.scrollTo(0, 100);
}
window.addEventListener('load', doTest, false);
</script>
</head>
<body>
<div class="group">
<div class="indicator box" style="top: 110px;"></div>
<div class="container">
<div class="sticky box"></div>
</div>
</div>
<div class="group" style="top: 100px">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box"></div>
</div>
</div>
<div class="group" style="top: 200px">
<div class="indicator box" style="top: 37px;"></div>
<div class="container">
<div class="sticky box"></div>
</div>
</div>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment