html - 输入字段在 Chrome 和 Firefox 中显示不同

标签 html css

我在 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;
}

http://jsfiddle.net/J8dSN/12/

关于html - 输入字段在 Chrome 和 Firefox 中显示不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18582606/

相关文章:

javascript - 防止按钮对 html 输入和按钮标签的影响

javascript - 如何使用 HTML 为关键字着色?

JavaFX 可编辑表格 View : How to change size and css of the TextField inside of TableCell?

javascript - 动态更改 iframe 内的元素样式

html - Bootstrap 列在 IE11 (Flex) 中不起作用

html - 如何在不使用边距或文本对齐的情况下将元素居中对齐

javascript - JQuery 切换图标

html - :-webkit-any-link { text-decoration: underline; } can only be written by inline-style, 为什么?

javascript - 如何使 if 语句中的 "document.write"在同一 html 页面而不是新的空白页面上工作?

javascript - 在 javascript 函数中使用选择器 "$(this).find()"jQuery