--- title: scroll-snap-points-x slug: Web/CSS/scroll-snap-points-x tags: - CSS - css snap translation_of: Web/CSS/scroll-snap-points-x ---
scroll-snap-points-x CSS属性定义滚动容器中内容的snap点的水平位置。
{{cssinfo}}
/* 关键值 */ scroll-snap-points-x: none; /* 重复的snap点 */ scroll-snap-points-x: repeat(400px); /* 全局值 */ scroll-snap-points-x: inherit; scroll-snap-points-x: initial; scroll-snap-points-x: unset;
nonerepeat(<长度>)<div id="container"> <div>1</div> <div>2</div> <div>3</div> </div>
#container {
width: 200px;
overflow: auto;
white-space: nowrap;
scroll-snap-points-x: repeat(100%);
scroll-snap-type: mandatory;
font-size: 0;
}
#container > div {
width: 200px;
height: 200px;
display: inline-block;
line-height: 200px;
text-align: center;
font-size: 100px;
}
#container > div:nth-child(even) {
background-color: #87ea87;
}
#container > div:nth-child(odd) {
background-color: #87ccea;
}
{{EmbedLiveSample("Example", 220, 220)}}
此属性曾定义在early draft of CSS Scroll Snap Points Module中,但是后来在in favor of element-based snapping规范中被移除。