【发布时间】:2018-11-08 20:36:36
【问题描述】:
我在 -webkit 和其他浏览器之间的 select 元素上发现了这种不一致的行为。元素内文本的间距与其他输入元素不一致。 (见示例)。选择在左侧有一个额外的 ~2px 间距。因此不会与上面的输入元素水平对齐。
Chrome 工作正常,元素中的文本水平对齐。
Firefox 不能与上面的输入完全水平对齐。
元素上的填充是相同的。只有这个我无法解释的间距存在于选择元素中,而不是 -webkit 浏览器。我已经检查过了:
- Safari(没有填充对齐)
- Chrome(无填充对齐)
- 火狐
- 边缘
- 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>
2018 年 8 月更新
经过一番头痛并在网上搜索后,我找到了两个答案 here 和 here 似乎“回答”了我的问题。答案就像我认为的浏览器渲染不一致。不幸的是,没有简单的 css 方法来解决这个问题。
【问题讨论】:
-
在您的示例图像中,“无法解释”的空间在哪里?这两个图像对我来说看起来几乎一样。
:| -
它们都有相同的高度和相同的宽度我在这里没有发现任何奇怪的地方
-
选择中的文本左侧有一个~2px的空间。它们在左侧不能很好地对齐。虽然间距相同。将更新我的问题以更好地澄清问题