html - 如何修复桌面和移动设备上不一致的占位符文本垂直对齐方式?

标签 html css alignment vertical-alignment placeholder

我的输入占位符文本在 Firefox 和 Chrome 桌面中正确垂直对齐。但在 Safari 桌面加上 Firefox Mobile、Chrome Mobile 和 Safari Mobile 上,文本太高了。

我试过 padding 和 line-height,但没能解决。

这是代码 - 在移动设备上查看它以查看问题:

https://codepen.io/paulspelman/pen/XGvVrE

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  padding: 0;
  margin: 0;
  color: #00bb80;
  background: #101010;
}

.wrapper {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
  max-width: 900px;
  font-family: sans-serif;
  text-align: center;
  width: 70%;
}

.input-holder {
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  height: 4rem;
  margin: 0 auto 2rem auto;
}

input {
  height: 4rem;
  width: 12rem;
  font-size: 2rem;
  font-weight: 300;
  text-align: left;
  padding: 0 0 0.2rem 1rem;
  margin-left: 0.5rem;
  color: #9b9b9b;
  background: #101010;
  border: 1px solid #434343;
  border-right: 0;
  border-radius: 0;
}

input::-webkit-input-placeholder {
  font-size: 1.1rem;
  font-weight: 400;
  position: relative;
  top: -0.3rem;
  color: #9b9b9b;
}

input:-ms-input-placeholder {
  font-size: 1.1rem;
  font-weight: 400;
  position: relative;
  top: -0.3rem;
  color: #9b9b9b;
}

input::-ms-input-placeholder {
  font-size: 1.1rem;
  font-weight: 400;
  position: relative;
  top: -0.3rem;
  color: #9b9b9b;
}

input::placeholder {
  font-size: 1.1rem;
  font-weight: 400;
  position: relative;
  top: -0.3rem;
  color: #9b9b9b;
}

.dollar-sign {
  color: #9b9b9b;
  font-size: 2rem;
  font-weight: 300;
  margin: 0;
  padding-bottom: 0.4rem;
}

button {
  height: 4rem;
  font-size: 1.5rem;
  width: 4rem;
  font-weight: 400;
  text-align: center;
  background-color: #797979;
  color: #101010;
  border: 0;
  padding: 0;
}
<div class="wrapper"> 


    <div class="input-holder">
        <p class="dollar-sign">$</p>
        <input type="text" class="user-input" placeholder=" Placeholder text" maxlength="4" value="" autocomplete="off">
        <button class="calculate-button">&rarr;</button>
    </div>

</div>

最佳答案

有一个小技巧可以修复它。您需要指定:

@supports(font-synthesis: inherit) { // not supported by Chrome but supported by Safari
   input::placeholder {
     line-height:3em
  }
}

Demo

关于html - 如何修复桌面和移动设备上不一致的占位符文本垂直对齐方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55408575/

相关文章:

html - CSS 选择器测试器有效性

javascript - 带有 DIV 的水平幻灯片

css - 主div两侧的div,填充剩余空间

html - 正如 Bootstrap 网格所说,在移动设备中以不同方式对齐缩略图?

php - 使用 TCPDF 和特定 div 作为内容创建 PDF

html - 居中联系表单内容

javascript - Bootstrap 选择自定义动态选项

html - 在css中将div剪辑成不规则形状的方法

jquery - 在固定的维度 div 中水平和垂直居中内容

html - 如何将右容器与左容器的上边距对齐?