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

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

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 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