横滑轮播,每次滑动都停在卡片边界。
<div class="snap"><i>1</i><i>2</i><i>3</i></div>.snap {
display: flex; gap: 8px;
overflow-x: auto;
scroll-snap-type: x mandatory;
scrollbar-width: none;
width: 220px;
border-radius: 10px;
}
.snap::-webkit-scrollbar { display: none; }
.snap i {
flex: 0 0 100%;
scroll-snap-align: center;
height: 76px; border-radius: 10px;
display: grid; place-items: center;
background: linear-gradient(135deg, #2b57ff, #7a4bff);
color: #fff; font: 700 16px/1 ui-monospace, monospace;
font-style: normal;
}复制后可直接使用;如果要放进已有项目,注意把类名改成你项目里的命名,避免冲突。