Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda