CSS Scroll-snap with children nested in overflow: hidden element

Viewed 717

Is it possible to apply scroll-snap to grand-children nested in children with overflow applied ? I can't seem to make it work.

What I aim to do is have a list of div with each a fixed height on which the viewport should snap vertically

html {
  margin: 0;
  scroll-snap-type: y mandatory;
  overflow-x: hidden;
}
.horizontal-scroll {
  max-width: 100vw;
}

.child {
  width: 150vw;
  scroll-snap-align: center;
  height: 80vh;
  background-color: rgb(143, 204, 241);
  padding: 20px 15px;
}
.child:nth-child(even) {
  background-color: rgb(133, 243, 155);
}
<!DOCTYPE html>
<html>
  <head
  </head>
  <body>
<div class="horizontal-scroll">
  <div class="child">
    <h2>Section</h2>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel laboriosam cupiditate vero, harum, ab facere ipsa mollitia exercitationem impedit alias nulla magnam aut tempore repudiandae
      dolores. Sit maiores nemo ea.
    </p>
  </div>  <div class="child">
    <h2>Section</h2>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel laboriosam cupiditate vero, harum, ab facere ipsa mollitia exercitationem impedit alias nulla magnam aut tempore repudiandae
      dolores. Sit maiores nemo ea.
    </p>
  </div>  
  <div class="child">
    <h2>Section</h2>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel laboriosam cupiditate vero, harum, ab facere ipsa mollitia exercitationem impedit alias nulla magnam aut tempore repudiandae
      dolores. Sit maiores nemo ea.
    </p>
  </div>
</div>
  </body>
</html>

Homewer, I would also like the content to be horizontally-scrollable - as their content stretch beyond the viewport width.

They must also scroll together, so using overflow-x on each of them is not possible here. To do so, I've wrapped the child in a scrollable-wrapper that is horizontally scrollable ( overflow-x : scroll ) and have a fixed width.

And this breaks the vertical scroll snap.

Could someone tell me if there's something I missed or if there's an alternative ?

Note : since each child have a fixed height, I would not mind using scroll-snap-points-y but it has been totally dropped on almost every browser. Is there a way to reproduce this behaviour ?

Edit : I might try this for the snap-point. It's jQuery based.

Vertical scrolling snap jQuery

Snippet

html {
  margin: 0;
  scroll-snap-type: y mandatory;
overflow-x: hidden;
}
.horizontal-scroll {
  max-width: 100vw;
  overflow-x: scroll;
}

.child {
  width: 150vw;
  scroll-snap-align: center;
  height: 80vh;
  background-color: rgb(143, 204, 241);
  padding: 20px 15px;
}
.child:nth-child(even) {
  background-color: rgb(133, 243, 155);
}
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
<div class="horizontal-scroll">
  <div class="child">
    <h2>Section</h2>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel laboriosam cupiditate vero, harum, ab facere ipsa mollitia exercitationem impedit alias nulla magnam aut tempore repudiandae
      dolores. Sit maiores nemo ea.
    </p>
  </div>  <div class="child">
    <h2>Section</h2>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel laboriosam cupiditate vero, harum, ab facere ipsa mollitia exercitationem impedit alias nulla magnam aut tempore repudiandae
      dolores. Sit maiores nemo ea.
    </p>
  </div>  
  <div class="child">
    <h2>Section</h2>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel laboriosam cupiditate vero, harum, ab facere ipsa mollitia exercitationem impedit alias nulla magnam aut tempore repudiandae
      dolores. Sit maiores nemo ea.
    </p>
  </div>
</div>
  </body>
</html>

0 Answers
Related