html - 如何在非活动输入字段中保持文本居中?
问题描述
当我点击远离字段时,我希望文本居中在输入字段中。现在,当我在字段内写东西时,它是从中心开始的——这很好。现在,当我离开场地或去另一个场地时,我想保持它居中。是否可以?谢谢你的帮助。
加分项:输入框的下边框可以向上移动吗?假设 2pxs up 以便它与字段周围的文本完美对齐?
input[type=text] {
background-color: #fff;
border-top: 0px;
border-right: 0px;
border-left: 0px;
border-bottom: 1px black dotted;
width: 100px;
}
input[type=text]:focus {
outline: none;
text-align: center;
}
<p>
Write something in here: <input type="text">. Thanks!
</p>
解决方案
把text-align:center
_ input[type=text]
_input[type=text]:focus
input[type=text] {
background-color: #fff;
border-top: 0px;
border-right: 0px;
border-left: 0px;
border-bottom: 1px black dotted;
width: 100px;
text-align: center;
}
input[type=text]:focus {
outline: none;
}
<p>
Write something in here: <input type="text">. Thanks!
</p>
推荐阅读
- javascript - Cookie 在同意之前设置
- microsoft-graph-api - 图表 - 是否有更简单/更快的方法来删除 SharePoint 列表中的所有项目?
- video - 使用 FFmpeg 创建单个视频表单 3 个单独的视频
- java - YAML 文件:读取 Yaml 文件并以相同格式写入文件
- swift - 了解闭包的目的
- httpclient - 在 Apache HttpClient 中,我如何知道 2 个请求是否使用相同的连接?
- sql - PostgreSQL 错误:返回集合的函数必须出现在 FROM 的顶层
- c# - 如何在棱镜 IContainerRegistry 中为 2 个接口注册相同的实例(= 单例)
- c# - 使用 Sum 和抽象函数从多个表 SQL 查询中获取记录
- c# - 如何检查当前上下文中是否允许执行函数?