纯 CSS 实现 time-picker 效果
Posted 前端精髓
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了纯 CSS 实现 time-picker 效果相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*
margin: 0;
padding: 0;
.container
display: flex;
position: relative;
z-index: 2;
.time
line-height: 24px;
overflow: auto;
height: 180px;
scroll-snap-type: y mandatory;
::-webkit-scrollbar
display: none;
.swap
display: flex;
height: 180px;
align-items: center;
justify-content: center;
position: relative;
.item
scroll-snap-align: center;
height: 60px;
line-height: 60px;
width: 40px;
text-align: center;
.line
position: absolute;
left: 0;
top: 60px;
width: 100%;
height: 60px;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
z-index: 1;
</style>
</head>
<body>
<div class="swap">
<div class="container">
<div class="time">
<div class="item"></div>
<div class="item">01</div>
<div class="item">02</div>
<div class="item">03</div>
<div class="item">04</div>
<div class="item">05</div>
<div class="item">06</div>
<div class="item">07</div>
<div class="item">08</div>
<div class="item">09</div>
<div class="item">10</div>
<div class="item"></div>
</div>
<div class="time">
<div class="item"></div>
<div class="item">01</div>
<div class="item">02</div>
<div class="item">03</div>
<div class="item">04</div>
<div class="item">05</div>
<div class="item">06</div>
<div class="item">07</div>
<div class="item">08</div>
<div class="item">09</div>
<div class="item">10</div>
<div class="item"></div>
</div>
</div>
<div class="line"></div>
</div>
</body>
</html>
了解scroll-snap-type:https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type
以上是关于纯 CSS 实现 time-picker 效果的主要内容,如果未能解决你的问题,请参考以下文章