css - 文本输入中自动填充的 CSS 字体系列问题
问题描述
我正在尝试为输入设置等宽字体,但是当自动填充启动并在自动填充下拉菜单选项之间切换时,文本输入的自动填充状态内的字体系列不会显示为指定的等宽字体,请参阅到此代码并将字体系列更改为等宽以描绘我的问题(我正在使用 Chrome btw): CSS 技巧的 Codepen 示例
/* Change autocomplete styles in WebKit */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
border: 1px solid green;
-webkit-text-fill-color: green;
-webkit-box-shadow: 0 0 0px 1000px #000 inset;
transition: background-color 5000s ease-in-out 0s;
}
/* PRESENTATIONAL STYLES */
body {
background: #333;
color: #fff;
display: flex;
font-family: monospace;
font-size: 3em;
justify-content: center;
}
form {
padding: 50px 0;
width: 50%;
}
<form>
<div class="form-group">
<label for="exampleInputFirst">First Name</label>
<input type="text" class="form-control input-lg" id="exampleInputFirst">
</div>
<div class="form-group">
<label for="exampleInputLast">Last Name</label>
<input type="text" class="form-control input-lg" id="exampleInputLast">
</div>
<div class="form-group">
<label for="exampleInputEmail">Email Address</label>
<input type="email" class="form-control input-lg" id="exampleInputEmail">
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Submit</button>
</form>
解决方案
这里的解决方案是input:-webkit-autofill::first-line
选择器。
它允许您在鼠标悬停在自动完成元素上时覆盖默认系统字体(和字体大小)。
推荐阅读
- tensorflow - Tensorflow Serving:在基本路径 /models 下找不到可服务的 half_plus_two 的版本
- javascript - 这个while循环有什么问题?
- r - 我是新来的。我试图通过使用 for 循环使我的代码不那么复杂
- java - Java double - 某些小数位后只有零
- python-3.x - Python 3.8 sort - Lambda 函数对列表、字符串表现不同
- azure-devops - 使用 Azure DevOps 时,如何防止 FtpUpload@2 在 ftp 服务器上创建额外的根文件夹?
- sql - 在 case 语句中聚合“不是 GROUP BY 表达式”错误
- r - 如何在R中的列表中查找包含和不包含的单词
- java - 结合二维数组和一维数组
- python - 打印满足特定条件的值的 colname 和 rowname