选择表单元素内部文本间距

问题描述 投票:1回答:1

我在-webkit和其他浏览器之间的select元素上发现了这种不一致的行为。元素内部文本的间距与其他输入元素不一致。 (见例)。选择在左侧有额外的~2px间距。因此,不与上面的输入元件水平对齐。

Chrome工作正常,元素中的文字水平对齐。

Chrome select

Firefox无法与上面的输入完全水平对齐。

Firefox select

元素上的填充是相同的。只有这个间距我无法解释存在于-webkit浏览器之外的select元素中。我查了一下:

  • Safari(没有填充对齐)
  • 镀铬(没有衬垫对齐)
  • 火狐
  • 边缘
  • IE11

FF,Edge和IE11都有(对我来说)无法解释的间距。没有文字缩进,没有任何我能找到的解释这个额外空间的东西。

这是我的(简化)css输入和选择

html {
    font-size: 93.75%;
    line-height: 2;
    min-height: 100%;
    webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    padding: 0;
    position: relative;
    background-color: #fff;
}

* {
    box-sizing: border-box;
}

.form
{
  background: #f1f1f1;
  padding: 15px;
  margin: 30px;
  max-width: 250px;
border-radius: 3px;
}

.form__group + .form__group
{
  margin-top: 10px;
}

input[type="text"], input[type="email"], input[type="tel"], input[type="password"] {
    border: 1px solid #999;
    padding: 6.5px 14px;
    margin: 0;
    width: 100%;
    border-radius: 0;
    -webkit-appearance: none;
    line-height: inherit;
    border-radius: 3px;
    height: 3rem;
    font-size: 14px;
    line-height: 24px;
}

select {
    font-size: 14px;
    line-height: 24px;
    -webkit-appearance: none;
    -webkit-padding-end: 29px !important;
    -webkit-padding-start: 14px !important;
    -moz-appearance: none;
    -o-appearance: none;
    appearance: none;
    border: 1px solid #999;
    padding: 6.5px 29px 6.5px 14px;
    margin: 0;
    width: 100%;
    outline: 0;
    border-radius: 3px;
    background: #fff;
    color: #484A4E;
    cursor: pointer;
    height: 3rem;
    background-size: 30px 50px;
    background-position: right center;
    background-repeat: no-repeat;
    background-image: url(data:image/svg+xml;base64,PHN2ZyBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSdub25lJyB2aWV3Q…lsZT0nZmlsbDojREZFNEVDOycgcG9pbnRzPScxNSwxNyAxMCwyMiAyMCwyMicvPjwvc3ZnPg==);
}
<div class="form">
  <div class="form__group">
    <input type="text" name="example-input" value="" placeholder="Example input" />
  </div>
  <div class="form__group">
    <select name="example-select">
      <option value="">Example select</option>
      <option value="example">Example select item</option>
      <option value="another">Another one</option>
    </select>
  </div>
</div>

更新08/2018

经过一些更多的头痛和搜索网络后,我发现两个答案herehere似乎“回答”我的问题。答案就像我认为浏览器渲染不一致一样。不幸的是,没有简单的CSS方法来解决这个问题。

html css
1个回答
0
投票

请遵循基本准则。

* {box-sizing: border-box; padding: 0;margin: 0;}
© www.soinside.com 2019 - 2024. All rights reserved.