Solution 1 :

Your problem can be solved without position: fixed, keeping position: sticky.

Add position: relative for the body style:

body {
    ...
    position: relative;
}

And add bottom: 0 for .book selector. This will stretch this div to the very bottom of the body tag:

.book {
    ...
    bottom: 0;
}

Solution 2 :

Change

.book {
  position: absolute;
}

To:

.book {
  position: fixed;
}

And also remove position: sticky; from .book a


Codepen: https://codepen.io/manaskhandelwal1/pen/yLaROjq

Solution 3 :

Change the position to fixed to both and adjust margin top and right like below code

.book {
   position: fixed;
   height: 100%;
   z-index: 100;
   margin-top: 30px;
   margin-right: 150px;
   right: 0;
   top: 0;
 }

a tag code

.book a {
     position: fixed;
     text-decoration: none;
     color: #1e1e1e;
     border: 4px solid #cfac44;
     background: #cfac44;
     padding: 10px 15px;
     transition: .2s;
     -webkit-transition: .2s;
    }

Solution 4 :

I have change css, here below:

book {
    position: fixed;
    height: 100%;
    z-index: 100;
    margin-top: 0;
    margin-right: 0;
    right: 0;
    top: 0;
}

.book a {
    position: sticky;
    top: 0;
    text-decoration: none;
    color: #1e1e1e;
    border: 4px solid #cfac44;
    background: #cfac44;
    padding: 10px 15px;
    transition: 0.2s;
    -webkit-transition: 0.2s;
}

Problem :

I have a ‘Book Now’ button that sticks to the top of the viewport at 10px gap.
The parent element has height of 100%, which means scrolling past 100%-worth of height makes the ‘Book Now’ div scroll out of view. See here.

How can I make the parent element 100% of the full webpage height, so the ‘Book Now’ div always sticks to the top?

HTML:

<div class="book font">
        <a href="index.html">BOOK NOW</a>
</div>

CSS:

.book {
position: absolute;
height: 100%;
z-index: 100;
margin-top: 80px;
margin-right: 10px;
right: 0;
top: 0;
}

.book a {
    position: sticky;
    top: 10px;
    text-decoration: none;
    color: #1e1e1e;
    border: 4px solid #cfac44;
    background: #cfac44;
    padding: 10px 15px;
    transition: .2s;
    -webkit-transition: .2s;
}

Comments

Comment posted by link

Hi, thanks for this! worked perfectly. I have a new problem, I had to add ‘overflow-x: hidden’ to html, body in order to stop the background video of the site from extending outside of the body. This has now interfered with the sticky div which no longer sticks! Any ideas? edit:

Comment posted by ibb.co/98FwSTp

Hello. Remove

Comment posted by Jack Scott

Hi, thanks for the reply, this solves the position sticky but interferes with the background video! it still lets you scroll horizontally which I’m trying to fix

Comment posted by s.kuznetsov

It worked for me and the video did not go beyond the window. Ok. I’m very busy right now, but as soon as the time comes, I’ll look at the site again.

Comment posted by Jack Scott

Hiya, yeah it works perfectly in Chrome, the problem is specific to Safari. And I’ve seen another thread on stack overflow with a supposed fix ‘-webkit-position: sticky’ which doesn’t work.

By