运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <head> <style> #container { width: 80%; aspect-ratio: 3/1; padding: 40px 0; margin: auto; border: solid black 2px; overflow-x: hidden; overflow-y: scroll; scroll-snap-type: y mandatory; scroll-padding-block-start: 20px; } .blue { background-color: lightblue; width: 95%; aspect-ratio: 3/1; } .green { background-color: lightgreen; width: 80%; aspect-ratio: 4/1; } .blue, .green { margin: 2px; scroll-snap-align: start none; } </style> </head> <body> <h3>CSS scroll-padding-block-start property.</h3> <p>Scroll-padding-block-start property is set on the container element, so that snap position is offset by a padding from the start of the container in the block direction.</p> <p>In this case, snap position is set to start in block direction, so the element in focus should snap into place at the very top of the container. But instead, because of the scroll-padding-block-start value, the element in focus is offset by 20px distance from the start of the container to the child element.</p> <div id="container"> <div class="blue"></div> <div class="green"></div> <div class="blue"></div> <div class="green"></div> <div class="blue"></div> <div class="green"></div> <div class="blue"></div> </div> </body> </html>