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

146
Vistas
CSS horizontal scroll snap to TOP of a slide

(Edit: the JS in the original post was included by a mistake - it's now deleted)

I have a horizontal scroll working perfectly fine.

The problem is that my slides are vertical scrollable (and this is all good bc there's a lot of content) which means when I scroll down to the bottom of slide 1 and then scrolls horizontally to slide 2 the viewport does snap to the left of slide 2 but the viewport stays at the bottom of the slide. I want the viewport to snap to the TOP of slide 2 as well.

I haven't been able to find a solution to this, and there only seem to be start, end and center as working values for scroll-snap-align which doesn't solve my problem.

Does anyone know a way around this?

See the codesnippet below.

#slidesContainer {
  height: auto;
  width: auto;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  position: relative;
  overflow: scroll;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

#slides {
  color: black;
  width: 100%;
  height: auto;
  font-size: 100px;
  position: static;
  flex-grow: 0;
  flex-shrink: 0;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
<div id="slidesContainer">
  <div id="slides" style="background-color:blue;">Slide 1<br><br> Scroll down until there is no more text, then scroll right text text text text text text text text text text text text text </div>
  <div id="slides" style="background-color:green;">Slide 2<br><br>This text is not visible unless you scroll back up - this is the problem.</div>
  <div id="slides" style="background-color:yellow;">Slide 3<br><br></div>
</div>

Thanks a lot in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If I am understanding you correctly, this should work just fine. Essentially I added a custom scroll bar via CSS under the note /* manual scrollbar */. You can style it as you desire, but I just made it basic. Then you can get the horizontal scrollbar to the top of your elements using transform: rotateX(180deg); The notes I added with the additions in your CSS should help.

#slidesContainer {
  height: 100vh;
  width: auto;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  position: relative;
  overflow: scroll;
  /* important for manual scrollbar to show */
}

#slides {
  color: black;
  width: 100%;
  height: 100%;
  font-size: 100px;
  position: static;
  flex-grow: 0;
  flex-shrink: 0;
}


/* manual scrollbar */

#slidesContainer::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 0px;
}

#slidesContainer::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: rgba(0, 0, 0, .5);
  box-shadow: 0 0 1px rgba(255, 255, 255, .5);
}


/* Puts scrollbar at top */

div#slidesContainer {
  transform: rotateX(180deg);
}

div#slidesContainer * {
  transform: rotateX(180deg);
}


/* for good measures */

body {
  margin: 0;
}
<div id="slidesContainer">
  <div id="slides" style="background-color:blue;">Slide 1<br><br> text text text text text text text text text text text text text </div>
  <div id="slides" style="background-color:green;">Slide 2<br><br></div>
  <div id="slides" style="background-color:yellow;">Slide 3<br><br></div>
</div>

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