I have recently started to explore sticky
positioning. I am trying to get an image to stick to the top of the screen once it reaches the top of the page. Similar to this example. Note: Doing this in chrome.
Anyway, having implemented the code below, it is not working. It is simply staying at its original position at the top of the section as you scroll. I have tried not using a css-grid and changing the sizes around but this has not worked either. I feel like im doing something very basic wrong.
CSS
.offices-section {
display: grid;
grid-template-columns: 40% 60%;
&__photos {
height: 300vh;
&--one {
position: -webkit-sticky;
position: sticky;
top: 0;
}
}
&__content{
height: 300vh;
}
}
HTML
<section className="offices-section">
<div className="offices-section__photos">
<img src={officeOne} className="offices-section__photos--one" alt="office one" />
</div>
<div className="offices-section__content"></div>
</section>
Note: Im using React, so technically above is JSX. Thanks for any help in advance.