OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 | |
3 <html> | |
4 <head> | |
5 <style> | |
6 body { | |
7 margin: 0; | |
8 height: 2000px; | |
9 overflow: hidden; /* hide scrollbars */ | |
10 } | |
11 | |
12 .group { | |
13 display: inline-block; | |
14 position: relative; | |
15 width: 180px; | |
16 height: 500px; | |
17 } | |
18 | |
19 .container { | |
20 width: 150px; | |
21 height: 400px; | |
22 border: 2px solid black; | |
23 padding: 5px; | |
24 } | |
25 | |
26 .box { | |
27 width: 120px; | |
28 height: 120px; | |
29 } | |
30 | |
31 .sticky { | |
32 position: sticky; | |
33 top: 10px; | |
34 background-color: green; | |
35 } | |
36 | |
37 .indicator { | |
38 position: absolute; | |
39 top: 0; | |
40 left: 37px; | |
41 background-color: red; | |
42 } | |
43 </style> | |
44 <script> | |
45 function doTest() | |
46 { | |
47 window.scrollTo(0, 300); | |
48 } | |
49 window.addEventListener('load', doTest, false); | |
50 </script> | |
51 </head> | |
52 <body> | |
53 <!-- auto margins --> | |
54 <div class="group"> | |
55 <div class="indicator box" style="top: 110px;"></div> | |
56 <div class="container"> | |
57 <div class="sticky box" style="margin: auto;"></div> | |
58 </div> | |
59 </div> | |
60 | |
61 <!-- px margins --> | |
62 <div class="group"> | |
63 <div class="indicator box" style="top: 37px;"></div> | |
64 <div class="container"> | |
65 <div class="sticky box" style="margin: 20px;"></div> | |
66 </div> | |
67 </div> | |
68 | |
69 <!-- % margins --> | |
70 <div class="group"> | |
71 <div class="indicator box" style="top: 37px;"></div> | |
72 <div class="container"> | |
73 <div class="sticky box" style="margin: 20%;"></div> | |
74 </div> | |
75 </div> | |
76 | |
77 <!-- % margins --> | |
78 <div class="group"> | |
79 <div class="indicator box" style="top: 37px;"></div> | |
80 <div class="container" style="width: 200px;"> | |
81 <div class="sticky box" style="margin: 20%;"></div> | |
82 </div> | |
83 </div> | |
84 </body> | |
85 </html> | |
OLD | NEW |