What are the bare necessities for CSS snap scroll to work?
up vote
3
down vote
favorite
I've been trying to implement a super simple horizontal snap scroll (as shown here: https://css-tricks.com/practical-css-scroll-snapping ) yet I am consistently failing at that. I've probably searched through all the questions and answers here but none was of help.
My code is very simple, I am only declaring scroll-snap-type: y mandatory;
on the parent and scroll-snap-align: center;
on the child. And I am pretty sure it's not a browser issue (since I've tried it with many different browsers). What am I missing here? Or what do I not understand?
Here's my (not working) CodePen: https://codepen.io/anon/pen/XyNNGY
html:
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
css:
body {
margin: 0;
}
.parent {
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
Thanks a million already.
html css scroll-snap-points
add a comment |
up vote
3
down vote
favorite
I've been trying to implement a super simple horizontal snap scroll (as shown here: https://css-tricks.com/practical-css-scroll-snapping ) yet I am consistently failing at that. I've probably searched through all the questions and answers here but none was of help.
My code is very simple, I am only declaring scroll-snap-type: y mandatory;
on the parent and scroll-snap-align: center;
on the child. And I am pretty sure it's not a browser issue (since I've tried it with many different browsers). What am I missing here? Or what do I not understand?
Here's my (not working) CodePen: https://codepen.io/anon/pen/XyNNGY
html:
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
css:
body {
margin: 0;
}
.parent {
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
Thanks a million already.
html css scroll-snap-points
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I've been trying to implement a super simple horizontal snap scroll (as shown here: https://css-tricks.com/practical-css-scroll-snapping ) yet I am consistently failing at that. I've probably searched through all the questions and answers here but none was of help.
My code is very simple, I am only declaring scroll-snap-type: y mandatory;
on the parent and scroll-snap-align: center;
on the child. And I am pretty sure it's not a browser issue (since I've tried it with many different browsers). What am I missing here? Or what do I not understand?
Here's my (not working) CodePen: https://codepen.io/anon/pen/XyNNGY
html:
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
css:
body {
margin: 0;
}
.parent {
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
Thanks a million already.
html css scroll-snap-points
I've been trying to implement a super simple horizontal snap scroll (as shown here: https://css-tricks.com/practical-css-scroll-snapping ) yet I am consistently failing at that. I've probably searched through all the questions and answers here but none was of help.
My code is very simple, I am only declaring scroll-snap-type: y mandatory;
on the parent and scroll-snap-align: center;
on the child. And I am pretty sure it's not a browser issue (since I've tried it with many different browsers). What am I missing here? Or what do I not understand?
Here's my (not working) CodePen: https://codepen.io/anon/pen/XyNNGY
html:
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
css:
body {
margin: 0;
}
.parent {
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
Thanks a million already.
html css scroll-snap-points
html css scroll-snap-points
edited Nov 12 at 18:40
BoltClock♦
509k12511451190
509k12511451190
asked Nov 12 at 17:29
selmanbey
537
537
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
The element you designate as the scroll snap container needs to be the one that the scrollbar is attached to. In your case, the parent element doesn't have a scrollbar — the scrollbar belongs to the viewport and the parent is extending past the size of the viewport without generating its own scrollbar. The scroll-snap-type
property should therefore be applied to body
(or html
), not the parent:
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
add a comment |
up vote
1
down vote
Try it like this.
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The element you designate as the scroll snap container needs to be the one that the scrollbar is attached to. In your case, the parent element doesn't have a scrollbar — the scrollbar belongs to the viewport and the parent is extending past the size of the viewport without generating its own scrollbar. The scroll-snap-type
property should therefore be applied to body
(or html
), not the parent:
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
add a comment |
up vote
2
down vote
accepted
The element you designate as the scroll snap container needs to be the one that the scrollbar is attached to. In your case, the parent element doesn't have a scrollbar — the scrollbar belongs to the viewport and the parent is extending past the size of the viewport without generating its own scrollbar. The scroll-snap-type
property should therefore be applied to body
(or html
), not the parent:
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The element you designate as the scroll snap container needs to be the one that the scrollbar is attached to. In your case, the parent element doesn't have a scrollbar — the scrollbar belongs to the viewport and the parent is extending past the size of the viewport without generating its own scrollbar. The scroll-snap-type
property should therefore be applied to body
(or html
), not the parent:
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
The element you designate as the scroll snap container needs to be the one that the scrollbar is attached to. In your case, the parent element doesn't have a scrollbar — the scrollbar belongs to the viewport and the parent is extending past the size of the viewport without generating its own scrollbar. The scroll-snap-type
property should therefore be applied to body
(or html
), not the parent:
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
body {
margin: 0;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
width: 100vw;
height: 100vh;
background-color: pink;
}
.two {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child two'>Section 2</div>
<div class='child'>Section 3</div>
</div>
answered Nov 12 at 18:45
BoltClock♦
509k12511451190
509k12511451190
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
add a comment |
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
Thank you for the great explanation! That was really helpful.
– selmanbey
Nov 13 at 9:59
add a comment |
up vote
1
down vote
Try it like this.
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
add a comment |
up vote
1
down vote
Try it like this.
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
add a comment |
up vote
1
down vote
up vote
1
down vote
Try it like this.
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
Try it like this.
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
body {
margin: 0;
}
.parent {
max-height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
.child {
scroll-snap-align: center;
height: 100vh;
background-color: pink;
}
.child:nth-child(even) {
background-color: crimson;
}
<div class='parent'>
<div class='child'>Section 1</div>
<div class='child'>Section 2</div>
<div class='child'>Section 3</div>
</div>
edited Nov 12 at 18:15
answered Nov 12 at 17:39
Carle B. Navy
768216
768216
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
add a comment |
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
Thank you very much! I've accepted @BoltClock's answer for it helped me better to understand how scroll-snap works, but yours was also very helpful in reminding that you can make the parent scrollable (and thus snap-scrollable) by setting a max-height on it. So thanks a lot!
– selmanbey
Nov 13 at 9:50
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267227%2fwhat-are-the-bare-necessities-for-css-snap-scroll-to-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown