我在 Chrome 中测试过,它显示正常,但在 Firefox 中,输入框比预期的要大。
这是标记:
<div class="form-wrapper">
<input type="search" name="Ofsearch"
placeholder="Search here..." value=""/>
<button id="searchButton" type="submit">
Search
</button>
</div>
样式如下:
.form-wrapper {
height: 80px;
clear: both;
}
.form-wrapper input {
border-radius: 10px;
border: 5px solid #E5E4E2;
margin: 2px;
height: 40px;
vertical-align: middle;
padding: 20px;
margin-top: 15px;
width: 85%;
}
.form-wrapper button {
overflow: visible;
position: absolute;
float: right;
border: 0;
padding: 0;
height: 40px;
width: 110px;
border-radius: 0 3px 3px 0;
margin: 20px -118px;
}
这是 fiddle 中的示例.
从示例中可以看出,在 Chrome 和 Firefox 中,它们以不同的尺寸显示。
当我检查这个问题时,我发现 .form-wrapper input{ }
中的 padding:20px
导致了这个问题。但是,当我删除它时,Firefox 显示正常,但在 Chrome 中输入区域变小了。只是想知道,有什么方法可以让它在两种浏览器中显示相同。
最佳答案
这是有区别的,因为 Firefox 在 type="search"
输入上使用 box-sizing: content-box
,而 Chrome 使用 border-box
.
.form-wrapper input {
box-sizing: border-box;
}
关于html - 输入字段在 Chrome 和 Firefox 中显示不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18582606/