scroll-target-margin-003.html (1882B)
1 <!DOCTYPE html> 2 <html> 3 <title>focus() and scroll-margin with snapping off (y-axis)</title> 4 <link rel='author' title='Elika J. Etemad' href='http://fantasai.inkedblade.net/contact'> 5 <link rel='help' href='https://www.w3.org/TR/css-scroll-snap-1/#scroll-margin'> 6 <link rel='match' href='scroll-target-001-ref.html'> 7 <meta name="flags" content="should"> 8 <meta name='assert' 9 content="Test passes if scroll-margin is honored 10 on a scroll container with 'scroll-snap-type: none' 11 when scrolling an element into view 12 even if that operation is implied (in this case, by .focus())."> 13 <style type='text/css'> 14 .container { 15 border: solid blue 4px; 16 height: 4em; 17 overflow: auto; 18 19 /* to make failing more obvious */ 20 background: 0 1em / 100% 1em linear-gradient(red, red) repeat-x; 21 /* avoid anti-aliasing issues */ 22 font: 20px/1 sans-serif; 23 scrollbar-width: none; 24 } 25 .container > div, a { 26 height: 1em; 27 display: block; 28 outline: none; 29 } 30 #target { scroll-margin: 2em 0 1em; } /* snap area is exact fit for snapport */ 31 #stripe { background: green; } /* color part of the snap area */ 32 .fail { color: red; } /* make failing more obvious */ 33 34 /* emulate `scrollbar-width: none` for browsers that don't support it yet */ 35 ::-webkit-scrollbar { display: none; } 36 </style> 37 38 <div id='instructions'>Test passes if there is a green stripe across the second quarter of the box below and no red.</div> 39 40 <div class="container"> 41 <div></div> 42 <div></div> 43 <div></div> 44 <div></div> 45 <div class="fail">FAIL</div> 46 <div></div> 47 <div id="stripe"></div> 48 <a href="" id="target"></a> 49 <div></div> 50 <div class="fail">FAIL</div> 51 <div></div> 52 <div></div> 53 <div></div> 54 <div></div> 55 </div> 56 57 <script> 58 document.getElementById('target').focus(); 59 </script>