文本输入中自动填充的 CSS 字体系列问题

标签 css

我正在尝试将等宽字体设置为输入,但是当自动填充启动并在自动填充下拉菜单选项之间切换时,文本输入的自动填充状态中的字体系列不会显示为指定的等宽字体,请引用此代码并将字体系列更改为等宽字体以描述我的问题(顺便说一句,我正在使用 Chrome): Codepen example by CSS tricks

/* 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 选择器。

它允许您在鼠标悬停在自动完成元素上时覆盖默认系统字体(和字体大小)。

关于文本输入中自动填充的 CSS 字体系列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56184607/

相关文章:

html - 如何为移动网站修复响应式网站的高度?

html - 调整窗口大小时减少边距

javascript - 单选按钮不会以 html 形式显示

html - 使段落高度 100%

html - 如何防止 p 标签造成间隙(换行)

html - 左边是表格,右边是图片的列没有响应

css - 子菜单不会水平

css - 这个CSS发生了什么?

javascript - 更改 CSS 样式表的选择器属性

html - 带输入的下拉菜单