css - 如何使用 css 将电话输入分成不同的盒子(每个盒子一个数字)
问题描述
我想将每个数字输入拆分为单独的框。我想要它的视觉外观。
例如。当我们填写表格时,每个字母都在一个盒子里(每盒 1 个字母)。有没有办法在 CSS 中做到这一点。
请参考下图并查看 PAN 的输入,即成立日期。
我想使用 css 实现同样的事情,这样当用户输入时,每个字母都会出现在相应的块中。
解决方案
您可以使用背景渐变创建线条并将它们叠加在输入上。您需要使用等宽字体来保持所有内容对齐。您还需要maxlength
在输入上设置 a 。
.input-wrapper {
position: relative;
font-size: 2rem;
font-family: monospace;
}
.lines {
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
pointer-events: none;
/* create lines */
background-image: linear-gradient(
to right,
black 1px,
transparent 1px);
background-size: 2ch;
}
input {
display: block;
box-sizing: border-box;
border-width: 0 1px 1px;
border-color: black;
border-style: solid;
font: inherit;
padding: .25ch .5ch;
letter-spacing: 1ch;
max-width: 20ch;
}
/* for demo, ignore */
body {
margin: 0;
display: grid;
place-content: center;
min-height: 100vh;
}
<div class="input-wrapper">
<input type="tel" maxlength="9">
<span class="lines"></span>
</div>
推荐阅读
- android - 地理编码器对于 searchview 来说太慢了
- process - 在Linux中,如何在进行系统调用时检索进程的nice值和当前进程所有者的进程数?
- c# - 如何将“2013:11:21 15:11:04+02:00”解析为 DateTime
- node.js - 在 mac 上安装 XPC 连接时如何解决错误,以便我可以破解我的 furby?
- openpyxl - 当 x 为 None 时,条件(x 不是 None)失败
- python - 如何在行尾加括号
- typeorm - 如何使用 typeorm 编写下面的 psql 查询
- javascript - 是否有任何解决方案来解决内部服务器错误 500
- java - 使用 JFrame 的 jSerialComm 库和 UI 线程问题。端口.openPort(); 方法正在阻塞 UI 线程并且不允许在前端进行任何更新
- javascript - 如何根据 bool 值在反应应用程序中呈现信息?