Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda