Мне кажется, что здесь есть очевидный ответ, но я не могу понять, почему - в приведенном ниже примере макета - #one
не «подталкивается» на #three
?
Глядя на последний пример, приведенный в MDN , видно, что липкие элементы выталкивают друг друга из окна, тогда как здесь #one
& #three
, похоже, просто скользят друг по другу. Я чувствую, что это как-то связано с высотами (?), Но любая помощь в объяснении этого была бы признательна!
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
color: #000;
font: bold 20vw Helvetica, Arial, sans-serif;
}
.sticky {
position: sticky;
top: 0px;
}
#start {
width: 100%;
height: 50vh;
background: #fff;
}
#one {
height: 100vh;
width: 100%;
background: url('https://picsum.photos/900/1200/?random');
background-position: center;
background-size: cover;
}
#two {
width: 50%;
position: relative;
height: 100vh;
background: url('https://picsum.photos/800/1200/?random');
background-position: center;
background-size: cover;
}
#three {
width: 100%;
height: 100vh;
background: url('https://picsum.photos/700/1200/?random');
background-position: center;
background-size: cover;
}
<div id="start">
<h1>start</h1>
</div>
<div id="one" class="sticky img">
<h1>one</h1>
</div>
<div id="two" class="img">
<h1>two</h1>
</div>
<div id="three" class="sticky img">
<h1>three</h1>
</div>