html - 使用 CSS 垂直对齐输入占位符(或设置行高)

标签 html css

是否可以独立于父输入垂直对齐占位符?似乎没有办法让下面代码中的占位符出现在输入字段的垂直中心。我已经尝试了所有我能想到或在网上找到的 css 属性和解决方法,但输入和占位符上的不同字体大小似乎至少在 webkit 浏览器中是不可能的。

编辑: 左边是问题,右边是期望的外观: enter image description here

input {
  font-size: 22px;
  text-align: center;
  font-weight: bold;
  line-height: 44px;
}

input::-webkit-input-placeholder {
  font-size: 9px;
  text-transform: uppercase;
  color: #AAA;
}
<input type='text' placeholder='enter some text' />

最佳答案

最好的解决方案可能是简单地向占位符 CSS 规则添加一个 translate3d 转换,如下所示:

input {
  font-size: 22px;
  text-align: center;
  font-weight: bold;
  line-height: 44px;
}

input::-webkit-input-placeholder {
  font-size: 9px;
  text-transform: uppercase;
  color: #AAA;
  transform:translate3d(0,-4px,0)
}
<input type='text' placeholder='enter some text' />

关于html - 使用 CSS 垂直对齐输入占位符(或设置行高),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47357063/

相关文章:

android - 动态替换 HTML 参数的值

html - 路由事件时应用样式(过滤器)

javascript - 将 react-quill 用于博客应用程序,以便用户可以创建帖子。如何在 React 中正确显示一串 html 元素?

css - 在圆形溢出 div 中包含图像

javascript - 将 html 和 js 添加到 wordpress

javascript - HTML 按钮的作用类似于从键盘上按下的按键,并且在特定对象或整个网站上起作用

javascript - 文本框的客户端验证

javascript - 如何获取仅相对的 offsetParent()

css - CSS凸版效果

css - 如何在 Web 应用程序中渲染多个尺寸的同一图像?