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

218
Visualizações
How to stick an element to the top coming from above on scrolling?

I'm looking to create two sticky nav items. The blue one starts at the bottom of the page and sticks to the top of the page. The red one starts off screen at the top and then as the first one sticks it moves down the page and also sticks to the top.

Diagram of nav item positions

Pure CSS is the goal but I can also use javascript (React js). Thanks for any suggestions!

const Navbar = () => {
  return (
    <nav>
      <div></div>
      <div></div>
    </nav>
  )
}

// Render it
ReactDOM.render(
  <Navbar/>,
  document.getElementById("react")
);
body {
  margin: 0;
  height: 300vh;
}

nav {
  height: 50px;
  display: flex;
}

nav div {
  width: 100px;
  height: 100%;
}

nav div:first-child {
  background-color: red;

}

nav div:last-child {
  background-color: blue;
}
<div id="react"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const Navbar = () => {
  return (
    <div ></div>
     
   
  )
}

// Render it
ReactDOM.render(
  <Navbar/>,
  document.getElementById("react")
);
body {
  margin: 0;
  height: 300vh;
}
div{
 width:100px;
 height:100px;
 background-color: red; 
 position:sticky;
 top:50px;
 }
<div id="react"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

i think using position : sticky will solve you problem and do checkout https://developer.mozilla.org/en-US/docs/Web/CSS/position

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