Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
How to make an element sticky to both bottom and top of page using CSS

I'd like to make an element sticky such that it "sticks" to both the top of the page if the user scrolls past it, and to the bottom of the page before the user scrolls to it.

I understand how to make it sticky in one way, but not both

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found the answer myself by slightly augmenting this solution

HTML (unchanged):

BEFORE
<div class="hold">
  <div class="item">
    THING
  </div>
</div>
AFTER

CSS:

.hold {
  position: relative;
  margin-top: -2000px;
  margin-bottom: -2000px; /* Added this line */
  pointer-events: none;
}

.hold:before {
  content: "";
  display: block;
  height: 2000px;
}

/* Added the following block */ 

.hold:after {
  content: "";
  display: block;
  height: 2000px;
}


.item {
  pointer-events: initial;
  position: sticky;
  top:0; /* Made this addition */
  bottom: 0;
  z-index: 100;
}


about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!